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.
Dub Go 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.
main.go
Copy
Ask AI
func main() { // Update the link if same URL already exists or create a new link request := &operations.UpsertLinkRequestBody{ URL: "https://google.com", } ctx := context.Background() res, err := d.Links.Upsert(ctx, request) if err != nil { log.Fatal(err) } if res.LinkSchema != nil { fmt.Println(res.LinkSchema.ShortLink) }}
This way, you won’t have to worry about checking if the link already exists when you’re creating it.
Let’s retrieve analytics for a link using the Dub Go SDK.
main.go
Copy
Ask AI
func main() { // Retrieve the timeseries analytics for the last 7 days for a link request := operations.RetrieveAnalyticsRequest{ LinkId: "clv3o9p9q000au1h0mc7r6l63", Interval: "7d", GroupBy: "timeseries" } ctx := context.Background() res, err := d.Analytics.Retrieve(ctx, request) if err != nil { log.Fatal(err) } if res.OneOf != nil { // handle response }}