Dub Links API
Skill for integrating Dub Links API with strict scope limited to /links* endpoints.
API Overview
- Base URL:
https://api.dub.co
- Auth: Bearer token required
- Header:
Authorization: Bearer <DUB_API_KEY>
- Response format: JSON
- Scope: Links endpoints only
- Docs:
https://dub.co/docs/api-reference/endpoint/create-a-link
- Token docs (onboarding):
https://dub.co/docs/api-reference/tokens
- Local snapshot:
references/openapi-spec.json
API Key Onboarding
Use this flow when the user does not have an API key yet:
- Create a Dub account/workspace (if needed).
- Go to the dashboard token section (per docs):
https://dub.co/docs/api-reference/tokens
- Generate an API key and export it in shell:
- Validate credentials with a Links endpoint:
curl -s -H "Authorization: Bearer $DUB_API_KEY" "https://api.dub.co/links/count" | jq '.'
Useful onboarding note: if initial signup is needed, this referral can be used:
https://refer.dub.co/agents
Links Endpoints
1) Create
POST /links
- Creates a link in the authenticated workspace.
- Minimum recommended body:
url.
curl -s -X POST "https://api.dub.co/links" \
-H "Authorization: Bearer $DUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}' | jq '.'
2) Update
PATCH /links/{linkId}
- Updates an existing link by
linkId (also accepts externalId prefixed with ext_).
curl -s -X PATCH "https://api.dub.co/links/{linkId}" \
-H "Authorization: Bearer $DUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/new"}' | jq '.'
3) Upsert
PUT /links/upsert
- If a link with the same URL exists, returns/updates it; otherwise creates it.
curl -s -X PUT "https://api.dub.co/links/upsert" \
-H "Authorization: Bearer $DUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}' | jq '.'
4) Delete
DELETE /links/{linkId}
- Deletes a link by
linkId (also accepts externalId prefixed with ext_).
- Response:
{"id": "string"}.
curl -s -X DELETE "https://api.dub.co/links/{linkId}" \
-H "Authorization: Bearer $DUB_API_KEY" | jq '.'
5) Retrieve one
GET /links/info
- Retrieves a link by one of these selectors:
domain + key
linkId
externalId
curl -s "https://api.dub.co/links/info?domain=acme.link&key=promo" \
-H "Authorization: Bearer $DUB_API_KEY" | jq '.'
6) List
GET /links
- Returns paginated list with filters.
- Common query params:
domain, search, tagIds, tagNames, folderId, userId, tenantId, showArchived, page, pageSize (default: 100, max: 100), sortBy (createdAt|clicks|saleAmount|lastClicked), sortOrder (asc|desc).
curl -s "https://api.dub.co/links?page=1&pageSize=100&sortBy=createdAt&sortOrder=desc" \
-H "Authorization: Bearer $DUB_API_KEY" | jq '.'
7) Count
GET /links/count
- Returns number of links for the provided filters.
- Common query params:
domain, search, tagIds, tagNames, folderId, userId, tenantId, showArchived, groupBy (domain|tagId|userId|folderId).
curl -s "https://api.dub.co/links/count?domain=acme.link" \
-H "Authorization: Bearer $DUB_API_KEY" | jq '.'
8) Bulk create
POST /links/bulk
- Creates up to 100 links.
- Body: array of objects (each item should include
url).
curl -s -X POST "https://api.dub.co/links/bulk" \
-H "Authorization: Bearer $DUB_API_KEY" \
-H "Content-Type: application/json" \
-d '[{"url":"https://example.com/a"},{"url":"https://example.com/b"}]' | jq '.'
9) Bulk update
PATCH /links/bulk
- Updates up to 100 links.
- Body requires
data; target selection via linkIds or externalIds.
curl -s -X PATCH "https://api.dub.co/links/bulk" \
-H "Authorization: Bearer $DUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"linkIds":["lnk_123","lnk_456"],"data":{"archived":true}}' | jq '.'
10) Bulk delete
DELETE /links/bulk
- Deletes up to 100 links. Non-existing IDs are ignored. Irreversible.
- Required query param:
linkIds (comma-separated).
- Response:
{"deletedCount": number}.
curl -s -X DELETE "https://api.dub.co/links/bulk?linkIds=lnk_123,lnk_456" \
-H "Authorization: Bearer $DUB_API_KEY" | jq '.'
Key Fields
Common response fields (from LinkSchema):
id
domain
key
shortLink
url
createdAt
updatedAt
archived
externalId
tags
folderId
Result shapes by endpoint:
GET /links: array of links
GET /links/count: number
- Bulk endpoints: array/object depending on operation
Recommended Workflow
- Detect intent: create/update/upsert/delete/get/list/count/bulk.
- Validate minimum inputs (
url, linkId, filters, bulk ids).
- Execute request with
curl -s and Bearer header.
- Parse with
jq and verify logical operation result.
- Respond first with a useful snapshot:
id, shortLink, url, and archived status when relevant.
- For lists, provide a short table with relevant columns.
- Keep strict scope on
/links*.
Error Handling
- 401/403: missing, invalid, or unauthorized token.
- 404: link not found for
linkId or GET /links/info criteria.
- 422: invalid payload (missing/invalid fields).
- 429: rate limited; respect
Retry-After if present.
- Network/timeout: retry up to 2 times with short delay.
- Unexpected JSON: return minimal raw output and warn about inconsistency.
Presenting Results
Recommended output format:
- Executive summary (action + result).
- Short table for multiple links:
id | domain | key | shortLink | url | createdAt
- For bulk operations:
- requested total, processed total, errors if any.
- Clarify data is scoped to the authenticated workspace.
Out of Scope
This skill must not use:
- Analytics, events, conversions, partners, customers, commissions, payouts endpoints.
- Domains, folders, tags endpoints.
/tokens/* endpoints (including /tokens/embed/referrals).
The tokens page is used only for API key onboarding, not as operational scope.
OpenAPI Spec
Use references/openapi-spec.json as the stable local source for methods, paths, parameters, and schemas.
1---2name: dub-links-api3description: Integrates Dub Links API endpoints to create, update, delete, retrieve, list, count, and run bulk operations on short links. Use when the user asks for "dub links api", "create link dub", "upsert link dub", "list links", "count links", "bulk links", or lookups by linkId/domain+key/externalId.4---5
6# Dub Links API
7
8Skill for integrating Dub Links API with strict scope limited to `/links*` endpoints.
9
10## API Overview
11
12- **Base URL**: `https://api.dub.co`
13- **Auth**: Bearer token required
14- **Header**: `Authorization: Bearer <DUB_API_KEY>`
15- **Response format**: JSON
16- **Scope**: Links endpoints only
17- **Docs**: `https://dub.co/docs/api-reference/endpoint/create-a-link`
18- **Token docs (onboarding)**: `https://dub.co/docs/api-reference/tokens`
19- **Local snapshot**: `references/openapi-spec.json`
20
21## API Key Onboarding
22
23Use this flow when the user does not have an API key yet:
24
251. Create a Dub account/workspace (if needed).
262. Go to the dashboard token section (per docs):
27 - `https://dub.co/docs/api-reference/tokens`
283. Generate an API key and export it in shell:
29 - `export DUB_API_KEY="..."`
304. Validate credentials with a Links endpoint:
31 - `curl -s -H "Authorization: Bearer $DUB_API_KEY" "https://api.dub.co/links/count" | jq '.'`
32
33Useful onboarding note: if initial signup is needed, this referral can be used:
34`https://refer.dub.co/agents`
35
36## Links Endpoints
37
38### 1) Create
39
40- `POST /links`
41- Creates a link in the authenticated workspace.
42- Minimum recommended body: `url`.
43
44```bash
45curl -s -X POST "https://api.dub.co/links" \
46 -H "Authorization: Bearer $DUB_API_KEY" \
47 -H "Content-Type: application/json" \
48 -d '{"url":"https://example.com"}' | jq '.'
49```
50
51### 2) Update
52
53- `PATCH /links/{linkId}`
54- Updates an existing link by `linkId` (also accepts `externalId` prefixed with `ext_`).
55
56```bash
57curl -s -X PATCH "https://api.dub.co/links/{linkId}" \
58 -H "Authorization: Bearer $DUB_API_KEY" \
59 -H "Content-Type: application/json" \
60 -d '{"url":"https://example.com/new"}' | jq '.'
61```
62
63### 3) Upsert
64
65- `PUT /links/upsert`
66- If a link with the same URL exists, returns/updates it; otherwise creates it.
67
68```bash
69curl -s -X PUT "https://api.dub.co/links/upsert" \
70 -H "Authorization: Bearer $DUB_API_KEY" \
71 -H "Content-Type: application/json" \
72 -d '{"url":"https://example.com"}' | jq '.'
73```
74
75### 4) Delete
76
77- `DELETE /links/{linkId}`
78- Deletes a link by `linkId` (also accepts `externalId` prefixed with `ext_`).
79- Response: `{"id": "string"}`.
80
81```bash
82curl -s -X DELETE "https://api.dub.co/links/{linkId}" \
83 -H "Authorization: Bearer $DUB_API_KEY" | jq '.'
84```
85
86### 5) Retrieve one
87
88- `GET /links/info`
89- Retrieves a link by one of these selectors:
90 - `domain + key`
91 - `linkId`
92 - `externalId`
93
94```bash
95curl -s "https://api.dub.co/links/info?domain=acme.link&key=promo" \
96 -H "Authorization: Bearer $DUB_API_KEY" | jq '.'
97```
98
99### 6) List
100
101- `GET /links`
102- Returns paginated list with filters.
103- Common query params: `domain`, `search`, `tagIds`, `tagNames`, `folderId`, `userId`, `tenantId`, `showArchived`, `page`, `pageSize` (default: 100, max: 100), `sortBy` (`createdAt`|`clicks`|`saleAmount`|`lastClicked`), `sortOrder` (`asc`|`desc`).
104
105```bash
106curl -s "https://api.dub.co/links?page=1&pageSize=100&sortBy=createdAt&sortOrder=desc" \
107 -H "Authorization: Bearer $DUB_API_KEY" | jq '.'
108```
109
110### 7) Count
111
112- `GET /links/count`
113- Returns number of links for the provided filters.
114- Common query params: `domain`, `search`, `tagIds`, `tagNames`, `folderId`, `userId`, `tenantId`, `showArchived`, `groupBy` (`domain`|`tagId`|`userId`|`folderId`).
115
116```bash
117curl -s "https://api.dub.co/links/count?domain=acme.link" \
118 -H "Authorization: Bearer $DUB_API_KEY" | jq '.'
119```
120
121### 8) Bulk create
122
123- `POST /links/bulk`
124- Creates up to 100 links.
125- Body: array of objects (each item should include `url`).
126
127```bash
128curl -s -X POST "https://api.dub.co/links/bulk" \
129 -H "Authorization: Bearer $DUB_API_KEY" \
130 -H "Content-Type: application/json" \
131 -d '[{"url":"https://example.com/a"},{"url":"https://example.com/b"}]' | jq '.'
132```
133
134### 9) Bulk update
135
136- `PATCH /links/bulk`
137- Updates up to 100 links.
138- Body requires `data`; target selection via `linkIds` or `externalIds`.
139
140```bash
141curl -s -X PATCH "https://api.dub.co/links/bulk" \
142 -H "Authorization: Bearer $DUB_API_KEY" \
143 -H "Content-Type: application/json" \
144 -d '{"linkIds":["lnk_123","lnk_456"],"data":{"archived":true}}' | jq '.'
145```
146
147### 10) Bulk delete
148
149- `DELETE /links/bulk`
150- Deletes up to 100 links. Non-existing IDs are ignored. **Irreversible.**
151- Required query param: `linkIds` (comma-separated).
152- Response: `{"deletedCount": number}`.
153
154```bash
155curl -s -X DELETE "https://api.dub.co/links/bulk?linkIds=lnk_123,lnk_456" \
156 -H "Authorization: Bearer $DUB_API_KEY" | jq '.'
157```
158
159## Key Fields
160
161Common response fields (from `LinkSchema`):
162
163- `id`
164- `domain`
165- `key`
166- `shortLink`
167- `url`
168- `createdAt`
169- `updatedAt`
170- `archived`
171- `externalId`
172- `tags`
173- `folderId`
174
175Result shapes by endpoint:
176
177- `GET /links`: array of links
178- `GET /links/count`: number
179- Bulk endpoints: array/object depending on operation
180
181## Recommended Workflow
182
1831. Detect intent: create/update/upsert/delete/get/list/count/bulk.
1842. Validate minimum inputs (`url`, `linkId`, filters, bulk ids).
1853. Execute request with `curl -s` and Bearer header.
1864. Parse with `jq` and verify logical operation result.
1875. Respond first with a useful snapshot:
188 - `id`, `shortLink`, `url`, and `archived` status when relevant.
1896. For lists, provide a short table with relevant columns.
1907. Keep strict scope on `/links*`.
191
192## Error Handling
193
194- **401/403**: missing, invalid, or unauthorized token.
195- **404**: link not found for `linkId` or `GET /links/info` criteria.
196- **422**: invalid payload (missing/invalid fields).
197- **429**: rate limited; respect `Retry-After` if present.
198- **Network/timeout**: retry up to 2 times with short delay.
199- **Unexpected JSON**: return minimal raw output and warn about inconsistency.
200
201## Presenting Results
202
203Recommended output format:
204
205- Executive summary (action + result).
206- Short table for multiple links:
207 - `id | domain | key | shortLink | url | createdAt`
208- For bulk operations:
209 - requested total, processed total, errors if any.
210- Clarify data is scoped to the authenticated workspace.
211
212## Out of Scope
213
214This skill must not use:
215
216- Analytics, events, conversions, partners, customers, commissions, payouts endpoints.
217- Domains, folders, tags endpoints.
218- `/tokens/*` endpoints (including `/tokens/embed/referrals`).
219
220The tokens page is used only for API key onboarding, not as operational scope.
221
222## OpenAPI Spec
223
224Use `references/openapi-spec.json` as the stable local source for methods, paths, parameters, and schemas.