The length of the short link slug. Defaults to 7 if not provided. When used
with prefix, the total length of the key will be prefix.length + keyLength.
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.
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.
The identifier of the short link that is unique across your workspace. If set,
it can be used to identify your short link for client-side click tracking.
Deprecated: Use tagIds instead. The unique ID of the tag assigned to the
short link.
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.
index.py
Copy
Ask AI
res = d.links.create(request={ "url": "https://google.com", "external_id": "12345",})print(res.short_link)
Dub Python 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.
index.py
Copy
Ask AI
res = d.links.upsert(request={ "url": "https://google.com",})print(res.short_link)
This way, you won’t have to worry about checking if the link already exists when you’re creating it.
Let’s update an existing link using the Dub Python 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_).
index.py
Copy
Ask AI
# Update a link by its linkIdres = d.links.update(link_id="clx1gvi9o0005hf5momm6f7hj", request_body={ "url": "https://google.uk",})print(res.short_link)# Update a link by its externalIdres = d.links.update(external_id="ext_12345", request_body={ "url": "https://google.uk",})print(res.short_link)
Dub allows you to retrieve analytics for a link using the Dub Python SDK.
index.py
Copy
Ask AI
# Retrieve the timeseries analytics for the last 7 days for a linkres = d.analytics.retrieve(request={ "link_id": "clx1gvi9o0005hf5momm6f7hj", "interval": "7d", "group_by": "timeseries",})print(res)
Similarly, you can retrieve analytics for a link using the externalId field.
index.py
Copy
Ask AI
# Retrieve the timeseries analytics for the last 7 days for a linkres = d.analytics.retrieve(request={ "external_id": "ext_12345", "interval": "7d", "group_by": "timeseries",})print(res)