Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update SDK docs

Steven Teyc2e81946cf57
diff --git a/apps/docs/mint.json b/apps/docs/mint.json
index 98f114e6f2..9262e8c579 100644
--- a/apps/docs/mint.json
+++ b/apps/docs/mint.json
@@ -80,11 +80,11 @@
"api-reference/endpoint/create-a-new-link",
"api-reference/endpoint/retrieve-a-link",
"api-reference/endpoint/update-a-link",
+ "api-reference/endpoint/upsert-a-link",
"api-reference/endpoint/delete-a-link",
"api-reference/endpoint/retrieve-a-list-of-links",
"api-reference/endpoint/retrieve-number-of-links",
- "api-reference/endpoint/bulk-create-links",
- "api-reference/endpoint/upsert-a-link"
+ "api-reference/endpoint/bulk-create-links"
]
},
{
@@ -150,6 +150,7 @@
"sdks/typescript/links/create",
"sdks/typescript/links/get",
"sdks/typescript/links/update",
+ "sdks/typescript/links/upsert",
"sdks/typescript/links/delete",
"sdks/typescript/links/list",
"sdks/typescript/links/count",
diff --git a/apps/docs/sdks/typescript/links/create-many.mdx b/apps/docs/sdks/typescript/links/create-many.mdx
index 4b7819ed7b..0997c1ab78 100644
--- a/apps/docs/sdks/typescript/links/create-many.mdx
+++ b/apps/docs/sdks/typescript/links/create-many.mdx
@@ -4,6 +4,7 @@ title: "Create Many"
description: "Bulk create up to 100 links for the authenticated workspace."
---
+import LinkArguments from "/snippets/link-arguments.mdx";
import LinkResponse from "/snippets/link-response.mdx";
## Arguments
@@ -12,90 +13,7 @@ import LinkResponse from "/snippets/link-response.mdx";
The destination URL of the short link.
</ParamField>
-<ParamField body="domain" type="string">
- The domain of the short link. If not provided, the primary domain for the
- workspace will be used (or `dub.sh` if the workspace has no domains).
-</ParamField>
-
-<ParamField body="key" type="string">
- The short link slug. If not provided, a random 7-character slug will be
- generated.
-</ParamField>
-
-<ParamField body="externalId" type="string | null">
- This is the ID of the link in your database. If set, it can be used to
- identify the link in the future.
-</ParamField>
-
-<ParamField body="prefix" type="string">
- The prefix of the short link slug for randomly-generated keys (e.g. if prefix
- is `/c/`, generated keys will be in the `/c/:key` format). Will be ignored if
- key is provided.
-</ParamField>
-
-<ParamField body="archived" type="boolean" default={false}>
- Whether the short link is archived.
-</ParamField>
-
-<ParamField body="publicStats" type="boolean" default={false}>
- Whether the short link's stats are publicly accessible.
-</ParamField>
-
-<ParamField body="tagId" type="string | null">
- The unique ID of the tag assigned to the short link. This field is deprecated
- – use `tagIds` instead.
-</ParamField>
-
-<ParamField body="tagIds" type="string">
- The unique IDs of the tags assigned to the short link.
-</ParamField>
-
-<ParamField body="comments" type="string | null">
- The comments for the short link.
-</ParamField>
-
-<ParamField body="expiresAt" type="string | null">
- The date and time when the short link will expire at.
-</ParamField>
-
-<ParamField body="expiredUrl" type="string | null">
- The URL to redirect to when the short link has expired.
-</ParamField>
-
-<ParamField body="password" type="string | null">
- The password required to access the destination URL of the short link.
-</ParamField>
-
-<ParamField body="proxy" type="boolean" default="false">
- Whether the short link uses Custom Social Media Cards feature.
-</ParamField>
-
-<ParamField body="title" type="string | null">
- The title of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="description" type="string | null">
- The description of the short link generated via `api.dub.co/metatags`. Will be
- used for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="image" type="string | null">
- The image of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="rewrite" type="boolean" default={false}>
- Whether the short link uses link cloaking.
-</ParamField>
-
-<ParamField body="ios" type="string | null">
- The iOS destination URL for the short link for iOS device targeting.
-</ParamField>
-
-<ParamField body="android" type="string | null">
- The Android destination URL for the short link for Android device targeting.
-</ParamField>
+<LinkArguments />
## Response
diff --git a/apps/docs/sdks/typescript/links/create.mdx b/apps/docs/sdks/typescript/links/create.mdx
index f0a78070b4..9053e522d4 100644
--- a/apps/docs/sdks/typescript/links/create.mdx
+++ b/apps/docs/sdks/typescript/links/create.mdx
@@ -4,6 +4,7 @@ title: "Create"
description: "Create a new link for the authenticated workspace."
---
+import LinkArguments from "/snippets/link-arguments.mdx";
import LinkResponse from "/snippets/link-response.mdx";
## Arguments
@@ -12,90 +13,7 @@ import LinkResponse from "/snippets/link-response.mdx";
The destination URL of the short link.
</ParamField>
-<ParamField body="domain" type="string">
- The domain of the short link. If not provided, the primary domain for the
- workspace will be used (or `dub.sh` if the workspace has no domains).
-</ParamField>
-
-<ParamField body="key" type="string">
- The short link slug. If not provided, a random 7-character slug will be
- generated.
-</ParamField>
-
-<ParamField body="externalId" type="string | null">
- This is the ID of the link in your database. If set, it can be used to
- identify the link in the future.
-</ParamField>
-
-<ParamField body="prefix" type="string">
- The prefix of the short link slug for randomly-generated keys (e.g. if prefix
- is `/c/`, generated keys will be in the `/c/:key` format). Will be ignored if
- key is provided.
-</ParamField>
-
-<ParamField body="archived" type="boolean" default={false}>
- Whether the short link is archived.
-</ParamField>
-
-<ParamField body="publicStats" type="boolean" default={false}>
- Whether the short link's stats are publicly accessible.
-</ParamField>
-
-<ParamField body="tagId" type="string | null">
- The unique ID of the tag assigned to the short link. This field is deprecated
- – use `tagIds` instead.
-</ParamField>
-
-<ParamField body="tagIds" type="string">
- The unique IDs of the tags assigned to the short link.
-</ParamField>
-
-<ParamField body="comments" type="string | null">
- The comments for the short link.
-</ParamField>
-
-<ParamField body="expiresAt" type="string | null">
- The date and time when the short link will expire at.
-</ParamField>
-
-<ParamField body="expiredUrl" type="string | null">
- The URL to redirect to when the short link has expired.
-</ParamField>
-
-<ParamField body="password" type="string | null">
- The password required to access the destination URL of the short link.
-</ParamField>
-
-<ParamField body="proxy" type="boolean" default={false}>
- Whether the short link uses Custom Social Media Cards feature.
-</ParamField>
-
-<ParamField body="title" type="string | null">
- The title of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="description" type="string | null">
- The description of the short link generated via `api.dub.co/metatags`. Will be
- used for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="image" type="string | null">
- The image of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="rewrite" type="boolean" default={false}>
- Whether the short link uses link cloaking.
-</ParamField>
-
-<ParamField body="ios" type="string | null">
- The iOS destination URL for the short link for iOS device targeting.
-</ParamField>
-
-<ParamField body="android" type="string | null">
- The Android destination URL for the short link for Android device targeting.
-</ParamField>
+<LinkArguments />
## Response
diff --git a/apps/docs/sdks/typescript/links/update.mdx b/apps/docs/sdks/typescript/links/update.mdx
index 40d4ce7e76..a9153a1c6f 100644
--- a/apps/docs/sdks/typescript/links/update.mdx
+++ b/apps/docs/sdks/typescript/links/update.mdx
@@ -4,6 +4,7 @@ title: "Update"
description: "Edit a link for the authenticated workspace. Support partial updates."
---
+import LinkArguments from "/snippets/link-arguments.mdx";
import LinkResponse from "/snippets/link-response.mdx";
## Arguments
@@ -12,88 +13,7 @@ import LinkResponse from "/snippets/link-response.mdx";
The destination URL of the short link.
</ParamField>
-<ParamField body="domain" type="string">
- The domain of the short link.
-</ParamField>
-
-<ParamField body="key" type="string">
- The short link slug.
-</ParamField>
-
-<ParamField body="externalId" type="string | null">
- This is the ID of the link in your database. If set, it can be used to
- identify the link in the future.
-</ParamField>
-
-<ParamField body="prefix" type="string">
- The prefix of the short link slug for randomly-generated keys (e.g. if prefix
- is `/c/`, generated keys will be in the `/c/:key` format). Will be ignored if
- key is provided.
-</ParamField>
-
-<ParamField body="archived" type="boolean" default="false">
- Whether the short link is archived.
-</ParamField>
-
-<ParamField body="publicStats" type="boolean" default="false">
- Whether the short link's stats are publicly accessible.
-</ParamField>
-
-<ParamField body="tagId" type="string | null">
- The unique ID of the tag assigned to the short link. This field is deprecated
- – use `tagIds` instead.
-</ParamField>
-
-<ParamField body="tagIds" type="string">
- The unique IDs of the tags assigned to the short link.
-</ParamField>
-
-<ParamField body="comments" type="string | null">
- The comments for the short link.
-</ParamField>
-
-<ParamField body="expiresAt" type="string | null">
- The date and time when the short link will expire at.
-</ParamField>
-
-<ParamField body="expiredUrl" type="string | null">
- The URL to redirect to when the short link has expired.
-</ParamField>
-
-<ParamField body="password" type="string | null">
- The password required to access the destination URL of the short link.
-</ParamField>
-
-<ParamField body="proxy" type="boolean" default="false">
- Whether the short link uses Custom Social Media Cards feature.
-</ParamField>
-
-<ParamField body="title" type="string | null">
- The title of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="description" type="string | null">
- The description of the short link generated via `api.dub.co/metatags`. Will be
- used for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="image" type="string | null">
- The image of the short link generated via `api.dub.co/metatags`. Will be used
- for Custom Social Media Cards if proxy is true.
-</ParamField>
-
-<ParamField body="rewrite" type="boolean" default="false">
- Whether the short link uses link cloaking.
-</ParamField>
-
-<ParamField body="ios" type="string | null">
- The iOS destination URL for the short link for iOS device targeting.
-</ParamField>
-
-<ParamField body="android" type="string | null">
- The Android destination URL for the short link for Android device targeting.
-</ParamField>
+<LinkArguments />
## Response
@@ -102,14 +22,14 @@ import LinkResponse from "/snippets/link-response.mdx";
<RequestExample>
```ts
-// Update a link linkId
+// Update a link by its linkId
await dub.links.update("clv3o9p9q000au1h0mc7r6l63", {
- tagIds: ["clv3j1h7o00032u1ngo8luv84"],
+ url: "https://www.google.com",
});
-// Update a link externalId
+// Update a link by its externalId
await dub.links.update("ext_123", {
- tagIds: ["clv3j1h7o00032u1ngo8luv84"],
+ url: "https://www.google.com",
});
```
diff --git a/apps/docs/sdks/typescript/links/upsert.mdx b/apps/docs/sdks/typescript/links/upsert.mdx
new file mode 100644
index 0000000000..85c96fbef0
--- /dev/null
+++ b/apps/docs/sdks/typescript/links/upsert.mdx
@@ -0,0 +1,76 @@
+---
+title: "Upsert"
+"og:title": "dub.links.upsert - Upsert a new link - TypeScript SDK"
+description: "Upsert a link for the authenticated workspace by its URL. If a link with the same URL already exists, return it (or update it if there are any changes). Otherwise, a new link will be created."
+---
+
+import LinkArguments from "/snippets/link-arguments.mdx";
+import LinkResponse from "/snippets/link-response.mdx";
+
+## Arguments
+
+<ParamField body="url" type="string" required>
+ The destination URL of the short link.
+</ParamField>
+
+<LinkArguments />
+
+## Response
+
+<LinkResponse />
+
+<RequestExample>
+
+```ts
+const { shortLink } = await dub.links.upsert({
+ url: "https://www.google.com",
+});
+
+console.log(shortLink); // will always be https://dub.sh/xnjk23d
+```
+
+</RequestExample>
+
+<ResponseExample>
+
+```ts
+{
+ id: 'clv3o9p9q000au1h0mc7r6l63',
+ domain: 'dub.sh',
+ key: 'e7qzMuI',
+ externalId: "123",
+ url: 'https://www.google.com',
+ archived: false,
+ expiresAt: null,
+ expiredUrl: null,
+ password: null,
+ proxy: false,
+ title: null,
+ description: null,
+ image: null,
+ rewrite: false,
+ ios: null,
+ android: null,
+ geo: null,
+ publicStats: false,
+ tagId: null,
+ tags: [],
+ comments: null,
+ shortLink: 'https://dub.sh/e7qzMuI',
+ qrCode: 'https://api.dub.co/qr?url=https://dub.sh/e7qzMuI?qr=1',
+ utmSource: null,
+ utmMedium: null,
+ utmCampaign: null,
+ utmTerm: null,
+ utmContent: null,
+ userId: 'cludszk1h0000wmd2e0ea2b0p',
+ workspaceId: 'ws_clugls3tn000lwfotbpy30304',
+ clicks: 0,
+ lastClicked: null,
+ createdAt: '2024-04-17T10:31:00.398Z',
+ updatedAt: '2024-04-17T10:31:00.398Z',
+ projectId: 'clugls3tn000lwfotbpy30304'
+}
+```
+
+</ResponseExample>
diff --git a/apps/docs/snippets/link-arguments.mdx b/apps/docs/snippets/link-arguments.mdx
new file mode 100644
index 0000000000..d9b4acb88b
--- /dev/null
+++ b/apps/docs/snippets/link-arguments.mdx
@@ -0,0 +1,84 @@
+<ParamField body="domain" type="string">
+ The domain of the short link. If not provided, the primary domain for the
+ workspace will be used (or `dub.sh` if the workspace has no domains).
+</ParamField>
+
+<ParamField body="key" type="string">
+ The short link slug. If not provided, a random 7-character slug will be
+ generated.
+</ParamField>
+
+<ParamField body="externalId" type="string | null">
+ This is the ID of the link in your database. If set, it can be used to
+ identify the link in the future.
+</ParamField>
+
+<ParamField body="prefix" type="string">
+ The prefix of the short link slug for randomly-generated keys (e.g. if prefix
+ is `/c/`, generated keys will be in the `/c/:key` format). Will be ignored if
+ key is provided.
+</ParamField>
+
+<ParamField body="archived" type="boolean" default={false}>
+ Whether the short link is archived.
+</ParamField>
+
+<ParamField body="publicStats" type="boolean" default={false}>
+ Whether the short link's stats are publicly accessible.
+</ParamField>
+
+<ParamField body="tagId" type="string | null">
+ The unique ID of the tag assigned to the short link. This field is deprecated
+ – use `tagIds` instead.
+</ParamField>
+
+<ParamField body="tagIds" type="string">
+ The unique IDs of the tags assigned to the short link.
+</ParamField>
+
+<ParamField body="comments" type="string | null">
+ The comments for the short link.
+</ParamField>
+
+<ParamField body="expiresAt" type="string | null">
+ The date and time when the short link will expire at.
+</ParamField>
+
+<ParamField body="expiredUrl" type="string | null">
+ The URL to redirect to when the short link has expired.
+</ParamField>
+
+<ParamField body="password" type="string | null">
+ The password required to access the destination URL of the short link.
+</ParamField>
+
+<ParamField body="proxy" type="boolean" default={false}>
+ Whether the short link uses Custom Social Media Cards feature.
+</ParamField>
+
+<ParamField body="title" type="string | null">
+ The title of the short link generated via `api.dub.co/metatags`. Will be used
+ for Custom Social Media Cards if proxy is true.
+</ParamField>
+
+<ParamField body="description" type="string | null">
+ The description of the short link generated via `api.dub.co/metatags`. Will be
+ used for Custom Social Media Cards if proxy is true.
+</ParamField>
+
+<ParamField body="image" type="string | null">
+ The image of the short link generated via `api.dub.co/metatags`. Will be used
+ for Custom Social Media Cards if proxy is true.
+</ParamField>
+
+<ParamField body="rewrite" type="boolean" default={false}>
+ Whether the short link uses link cloaking.
+</ParamField>
+
+<ParamField body="ios" type="string | null">
+ The iOS destination URL for the short link for iOS device targeting.
+</ParamField>
+
+<ParamField body="android" type="string | null">
+ The Android destination URL for the short link for Android device targeting.
+</ParamField>
diff --git a/apps/web/lib/openapi/links/update-link.ts b/apps/web/lib/openapi/links/update-link.ts
index bee81d222c..02c97d22d2 100644
--- a/apps/web/lib/openapi/links/update-link.ts
+++ b/apps/web/lib/openapi/links/update-link.ts
@@ -10,7 +10,7 @@ export const updateLink: ZodOpenApiOperationObject = {
"x-speakeasy-max-method-params": 2,
summary: "Update a link",
description:
- "Update a link for the authenticated workspace. If there's no change, returns as is.",
+ "Update a link for the authenticated workspace. If there's no change, returns it as it is.",
requestParams: {
query: workspaceParamsSchema,
path: z.object({
diff --git a/apps/web/lib/openapi/links/upsert-link.ts b/apps/web/lib/openapi/links/upsert-link.ts
index 4e652e5911..a20a884500 100644
--- a/apps/web/lib/openapi/links/upsert-link.ts
+++ b/apps/web/lib/openapi/links/upsert-link.ts
@@ -9,7 +9,7 @@ export const upsertLink: ZodOpenApiOperationObject = {
"x-speakeasy-usage-example": true,
summary: "Upsert a link",
description:
- "Upsert a link for the authenticated workspace by its URL. If a link with the same URL already exists, returns as is if there's no change, or update it. Otherwise, a new link will be created.",
+ "Upsert a link for the authenticated workspace by its URL. If a link with the same URL already exists, return it (or update it if there are any changes). Otherwise, a new link will be created.",
requestParams: {
query: workspaceParamsSchema,
},