When creating links programmatically with Dub, you might want a way to associate them with a user or other identifiers in your system.

There are a few ways to do this, depending on your data structure:

MethodTypeDescriptionUse case
External IDOne-to-oneA unique identifier for a link within your system.Associating referral links with users in your system.
Tenant IDOne-to-manyThe ID of the tenant that created the link.Grouping all links created by a user/team in your system.
TagsMany-to-manyGrouping links by tagsOrganizing links by campaign / user / various for flexible, multi-dimensional filtering and reporting

External ID

In certain scenarios, it is essential to identify links within your system. For instance, you may need to associate a link with a user without storing the Dub link ID directly in your database (e.g. for referral links).

The externalId field serves this purpose effectively. It acts as a unique identifier within your database, allowing you to associate it with a corresponding link in Dub’s system.

Dub allows you to create links using an externalId and subsequently retrieve them by the same identifier.

externalId should be a unique value across your workspace. Trying to create a link with an externalId that already exists will result in a 409 conflict error error.

Here is an example of how to create a link with an externalId:

Let’s see how to retrieve a link by its externalId:

In addition to updating a link by its linkId, you can also update a link by its externalId.

Make sure to prefix the externalId with ext_. For example, if your externalId is 12345, you should pass ext_12345.

Retrieve analytics by externalId

You can also retrieve analytics for a link by its externalId.

Tenant ID

The ID of the tenant that created the link inside your system. If set, it can be used to fetch all links for a tenant. This is useful if you have a system that lets your users create their own links, and you want to group them on a tenant level.

Let’s see how to create a link with a tenant ID:

Here is how to retrieve links by tenant ID:


Tags

Tags are a great way to organize your links on Dub.co.

With tags, you can:

You can use either pass the tag ID or tag name to create a link with tags.

You can retrieve links by tag by tags.

Retrieve analytics by tags

You can retrieve analytics for a link by its tag by passing the IDs of the tags.