1. Prerequisites
To follow this guide, you will need to:2. Install and initialize the Dub TypeScript SDK
1
Install
Install the Dub TypeScript SDK using your preferred package manager:
2
Initialize
Then, initialize the Dub TypeScript SDK with your API key.You can now use the
lib/dub.ts
dub
object to interact with the Dub API.3. Create link
Let’s create a short link using the Dub TypeScript SDK.server/api/links.post.ts
externalId
field which is a unique identifier for the link in your own database to associate it with the link in Dub’s system.
server/api/links.post.ts
externalId
instead of the Dub linkId
.
4. Upsert link
Dub TypeScript SDK provides a method to upsert a link – where an existing link is updated if it exists, or a new link is created if it doesn’t. so you don’t have to worry about checking if the link already exists.server/api/links.put.ts
5. Update link
Let’s update an existing link using the Dub TypeScript 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 withext_
).
server/api/links.patch.ts
6. Retrieve analytics for link
Dub allows you to retrieve analytics for a link using the Dub TypeScript SDK.server/api/analytics.get.ts
externalId
field.
server/api/analytics.get.ts