The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add externalId examples for create link
Steven Tey0b7ea1558ed8
diff --git a/apps/docs/quickstart/django.mdx b/apps/docs/quickstart/django.mdxindex e34a51f469..57d65a4a5f 100644--- a/apps/docs/quickstart/django.mdx+++ b/apps/docs/quickstart/django.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Django and Dub Python S---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ pip install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/express.mdx b/apps/docs/quickstart/express.mdxindex 4d90f8066f..2aeed6d3ff 100644--- a/apps/docs/quickstart/express.mdx+++ b/apps/docs/quickstart/express.mdx@@ -4,15 +4,11 @@ description: "Learn how to create a short link using the Express and Dub Node.js---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites+import InstallNode from "/snippets/sdk-install-nodejs.mdx";<Prerequisites />-## 2. Install--<Install />+<InstallNode />Create a dub instance using the Dub Node.js SDK.diff --git a/apps/docs/quickstart/flask.mdx b/apps/docs/quickstart/flask.mdxindex 27308a8f28..b07fe8a9ce 100644--- a/apps/docs/quickstart/flask.mdx+++ b/apps/docs/quickstart/flask.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Flask and Dub Python SD---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ pip install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/go.mdx b/apps/docs/quickstart/go.mdxindex 546b8b7f20..4df4ea8b7e 100644--- a/apps/docs/quickstart/go.mdx+++ b/apps/docs/quickstart/go.mdx@@ -5,8 +5,6 @@ description: "Learn how to create a short link using the Dub Go SDK."import Prerequisites from "/snippets/sdk-prerequisites.mdx";-## 1. Prerequisites-<Prerequisites />## 2. Installdiff --git a/apps/docs/quickstart/laravel.mdx b/apps/docs/quickstart/laravel.mdxindex 8788b9716e..5106b272ee 100644--- a/apps/docs/quickstart/laravel.mdx+++ b/apps/docs/quickstart/laravel.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Laravel and Dub PHP SDK---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ composer require dub/dub-php>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/nextjs.mdx b/apps/docs/quickstart/nextjs.mdxindex f5cf458e03..242548ff09 100644--- a/apps/docs/quickstart/nextjs.mdx+++ b/apps/docs/quickstart/nextjs.mdx@@ -4,15 +4,11 @@ description: "Learn how to create a short link using the Next.js and Dub Node.js---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites+import InstallNode from "/snippets/sdk-install-nodejs.mdx";<Prerequisites />-## 2. Install--<Install />+<InstallNode />## 3. Create linkdiff --git a/apps/docs/quickstart/nodejs.mdx b/apps/docs/quickstart/nodejs.mdxindex 750e8833fa..96cbb5342f 100644--- a/apps/docs/quickstart/nodejs.mdx+++ b/apps/docs/quickstart/nodejs.mdx@@ -4,33 +4,42 @@ description: "Learn how to create a short link using the Dub Node.js SDK."---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites+import InstallNode from "/snippets/sdk-install-nodejs.mdx";+import LinkArguments from "/snippets/link-arguments.mdx";<Prerequisites />-## 2. Install--<Install />+<InstallNode />## 3. Create linkLet's create a short link using the Dub Node.js SDK.```typescript create-link.ts-import { Dub } from "dub";--const dub = new Dub({- token: process.env.DUB_API_KEY,- workspaceId: "ws_clugls3...",+const { shortLink } = await dub.links.create({+ url: "https://google.com",});+console.log(shortLink); // e.g. https://dub.sh/abc123+```++<Accordion title="Full list of available attributes for the Link model">+ <LinkArguments />+</Accordion>++## 3a. Create link with `externalId`++Optionally, you can also pass an `externalId` field which is a unique identifier for the link in your own database to associate it with the link in Dub's system.++```typescript create-link-external-id.tsawait dub.links.create({url: "https://google.com",+ externalId: "12345",});```+This will let you easily [update the link](#5-update-link) later on using the `externalId`, or [retrieve analytics](#6-retrieve-analytics-for-link) for it.+## 4. Upsert linkDub Node.js SDK provides a method to create or update a link so you don't have to worry about checking if the link already exists.@@ -47,17 +56,20 @@ console.log(shortLink); // will always be the same short linkLet's update an existing link using the Dub Node.js SDK.+You can do that in two ways:++- Using the link's `linkId` in Dub's system.+- Using the link's `externalId` in your own database (prefixed with `ext_`).+```typescript update-link.ts// Update a link by its linkIdawait dub.links.update("clv3o9p9q000au1h0mc7r6l63", {- url: "https://www.google.uk",- archived: true,+ url: "https://www.google.uk", // new URL});// Update a link by its externalId-await dub.links.update("ext_123", {- url: "https://www.google.uk",- archived: true,+await dub.links.update("ext_12345", {+ url: "https://www.google.uk", // new URL});```@@ -70,9 +82,24 @@ import { ClicksTimeseries } from "dub/models/components";// Retrieve the timeseries analytics for the last 7 days for a linkconst response = await dub.analytics.retrieve({- linkId: "LINK_ID",+ linkId: "clv3o9p9q000au1h0mc7r6l63",+ interval: "7d",+ groupBy: "timeseries",+});++const timeseries = response as ClicksTimeseries[];+```++Simliarly, you can retrieve analytics for a link using the `externalId` field.++```typescript get-analytics-external-id.ts+import { ClicksTimeseries } from "dub/models/components";++// Retrieve the timeseries analytics for the last 7 days for a link++const response = await dub.analytics.retrieve({+ externalId: "ext_12345",interval: "7d",- event: "clicks",groupBy: "timeseries",});diff --git a/apps/docs/quickstart/nuxt.mdx b/apps/docs/quickstart/nuxt.mdxindex 6cddaa0a4d..daa84a4173 100644--- a/apps/docs/quickstart/nuxt.mdx+++ b/apps/docs/quickstart/nuxt.mdx@@ -4,15 +4,11 @@ description: "Learn how to create a short link using the Nuxt and Dub Node.js SD---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites+import InstallNode from "/snippets/sdk-install-nodejs.mdx";<Prerequisites />-## 2. Install--<Install />+<InstallNode />Create a dub instance using the Dub Node.js SDK.diff --git a/apps/docs/quickstart/php.mdx b/apps/docs/quickstart/php.mdxindex d7d9d13f47..94ebcd7d2b 100644--- a/apps/docs/quickstart/php.mdx+++ b/apps/docs/quickstart/php.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Dub PHP SDK."---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ composer require dub/dub-php>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/python.mdx b/apps/docs/quickstart/python.mdxindex 77f4299324..4c035bf0d8 100644--- a/apps/docs/quickstart/python.mdx+++ b/apps/docs/quickstart/python.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Dub Python SDK."---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ pip install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/rails.mdx b/apps/docs/quickstart/rails.mdxindex 4ec08e22b9..95c5300df8 100644--- a/apps/docs/quickstart/rails.mdx+++ b/apps/docs/quickstart/rails.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Rails and Dub Ruby SDK.---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ gem install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/remix.mdx b/apps/docs/quickstart/remix.mdxindex 214b6373e7..bd9a793066 100644--- a/apps/docs/quickstart/remix.mdx+++ b/apps/docs/quickstart/remix.mdx@@ -4,15 +4,11 @@ description: "Learn how to create a short link using the Remix and Dub Node.js S---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites+import InstallNode from "/snippets/sdk-install-nodejs.mdx";<Prerequisites />-## 2. Install--<Install />+<InstallNode />Create a dub instance using the Dub Node.js SDK.diff --git a/apps/docs/quickstart/ruby.mdx b/apps/docs/quickstart/ruby.mdxindex 34a03ca79b..d172b7a71b 100644--- a/apps/docs/quickstart/ruby.mdx+++ b/apps/docs/quickstart/ruby.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Dub Ruby SDK."---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ gem install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/quickstart/sinatra.mdx b/apps/docs/quickstart/sinatra.mdxindex 769cd4c4e9..1278c4e77a 100644--- a/apps/docs/quickstart/sinatra.mdx+++ b/apps/docs/quickstart/sinatra.mdx@@ -4,9 +4,6 @@ description: "Learn how to create a short link using the Sinatra and Dub Ruby SD---import Prerequisites from "/snippets/sdk-prerequisites.mdx";-import Install from "/snippets/sdk-install-nodejs.mdx";--## 1. Prerequisites<Prerequisites />@@ -36,4 +33,4 @@ gem install dub>See the full example on GitHub.</Card>-</CardGroup>\ No newline at end of file+</CardGroup>diff --git a/apps/docs/sdks/typescript/links/create-many.mdx b/apps/docs/sdks/typescript/links/create-many.mdxindex 0997c1ab78..9033fca477 100644--- a/apps/docs/sdks/typescript/links/create-many.mdx+++ b/apps/docs/sdks/typescript/links/create-many.mdx@@ -9,10 +9,6 @@ import LinkResponse from "/snippets/link-response.mdx";## Arguments-<ParamField body="url" type="string" required>- The destination URL of the short link.-</ParamField>-<LinkArguments />## Responsediff --git a/apps/docs/sdks/typescript/links/create.mdx b/apps/docs/sdks/typescript/links/create.mdxindex 9053e522d4..bbaada3e43 100644--- a/apps/docs/sdks/typescript/links/create.mdx+++ b/apps/docs/sdks/typescript/links/create.mdx@@ -9,10 +9,6 @@ import LinkResponse from "/snippets/link-response.mdx";## Arguments-<ParamField body="url" type="string" required>- The destination URL of the short link.-</ParamField>-<LinkArguments />## Responsediff --git a/apps/docs/sdks/typescript/links/update.mdx b/apps/docs/sdks/typescript/links/update.mdxindex a9153a1c6f..394162d747 100644--- a/apps/docs/sdks/typescript/links/update.mdx+++ b/apps/docs/sdks/typescript/links/update.mdx@@ -9,10 +9,6 @@ import LinkResponse from "/snippets/link-response.mdx";## Arguments-<ParamField body="url" type="string">- The destination URL of the short link.-</ParamField>-<LinkArguments />## Responsediff --git a/apps/docs/sdks/typescript/links/upsert.mdx b/apps/docs/sdks/typescript/links/upsert.mdxindex 85c96fbef0..d3b6ca8782 100644--- a/apps/docs/sdks/typescript/links/upsert.mdx+++ b/apps/docs/sdks/typescript/links/upsert.mdx@@ -9,10 +9,6 @@ import LinkResponse from "/snippets/link-response.mdx";## Arguments-<ParamField body="url" type="string" required>- The destination URL of the short link.-</ParamField>-<LinkArguments />## Responsediff --git a/apps/docs/snippets/link-arguments.mdx b/apps/docs/snippets/link-arguments.mdxindex d9b4acb88b..3c6a573879 100644--- a/apps/docs/snippets/link-arguments.mdx+++ b/apps/docs/snippets/link-arguments.mdx@@ -1,3 +1,7 @@+<ParamField body="url" type="string" required>+ 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 theworkspace will be used (or `dub.sh` if the workspace has no domains).diff --git a/apps/docs/snippets/sdk-install-nodejs.mdx b/apps/docs/snippets/sdk-install-nodejs.mdxindex dad2c61e03..4c1eafe8a9 100644--- a/apps/docs/snippets/sdk-install-nodejs.mdx+++ b/apps/docs/snippets/sdk-install-nodejs.mdx@@ -1,3 +1,5 @@+## 2. Install and initialize the Dub Node.js SDK+Install the Dub Node.js SDK using your preferred package manager:<Tabs>@@ -8,20 +10,36 @@ Install the Dub Node.js SDK using your preferred package manager:```</Tab>+ <Tab title="yarn">- <Tab title="pnpm">-- ```bash- pnpm add dub+ ```bash+ yarn add dub```</Tab>- <Tab title="yarn">+ <Tab title="pnpm">- ```bash- yarn add dub+ ```bash+ pnpm add dub```</Tab></Tabs>++Then, initialize the Dub Node.js SDK with your API key.++```typescript lib/dub.ts+import { Dub } from "dub";++export const dub = new Dub({+ token: process.env.DUB_API_KEY, // optional, defaults to DUB_API_KEY env variable+ workspaceId: "ws_clugls3...",+});+```++You can now use the `dub` object to interact with the Dub API.++```typescript+import { dub } from "./lib/dub";+```diff --git a/apps/docs/snippets/sdk-prerequisites.mdx b/apps/docs/snippets/sdk-prerequisites.mdxindex eebf9e361a..33e52445bd 100644--- a/apps/docs/snippets/sdk-prerequisites.mdx+++ b/apps/docs/snippets/sdk-prerequisites.mdx@@ -1,3 +1,5 @@+## 1. Prerequisites+To follow this guide, you will need to:- [Create a Dub account](https://app.dub.co/login)