The ID of the link in your database. If set, it can be used to identify the
link in future API requests (must be prefixed with ext_ when passed as a
query parameter). This key is unique across your workspace.
An existing link can be updated by providing the id to the update method. This method returns the updated link as a response.You can use either the linkId or an externalId prefixed with ext_ which is a unique identifier for the link in your own database to associate it with the link in Dub’s system.
Copy
Ask AI
import { Dub } from "dub";export const dub = new Dub({ token: process.env.DUB_API_KEY,});const link = await dub.links.update("link_eBKA4MT44XnI17hYLchkjUOd", { url: "https://www.google.uk", // new URL});
Upserting a link is a combination of creating and updating a link. 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.This allows you to use the upsert method without the necessity of checking for the link’s existence beforehand.
Copy
Ask AI
import { Dub } from "dub";export const dub = new Dub({ token: process.env.DUB_API_KEY,});const link = await dub.links.upsert({ url: "https://google.com", // will always be the same short link});