Quickstart
This walk-through uses curl, so it works from any terminal. The same calls in Go,
JavaScript, Python, PHP and Ruby are on the SDKs page.
1. Create an API key
- In the app, open Profile → API keys and choose Create API key.
- Name it after what will use it, for example
quickstart. - Leave Data access on Account-wide.
- Under Permissions, turn on Read and Edit for Links, Read for
Analytics and Read for Workspace details (
links:read,links:write,analytics:read,workspaces:read). - Choose Create API key and copy the secret. It is shown only once.
Put it in an environment variable rather than in your code:
export SHORTN_API_KEY="sk_live_..."API keys explains which kind of key to create for a real integration, and how to keep it safe.
2. List your workspaces
Every link lives in a workspace. Ask which ones the key can reach:
curl https://app.shortn.link/api/v1/workspaces \
-H "Authorization: Bearer $SHORTN_API_KEY"{
"data": [
{
"public_id": "8c0f6b52-4d0e-4a71-9a3e-2f6d1c7b5a10",
"name": "Acme Marketing",
"slug": "acme-marketing",
"role": "owner",
"link_count": 120
}
]
}Responses here are shortened; the reference lists every field.
Keep the public_id of the workspace you want to use.
3. Create a link
curl -X POST https://app.shortn.link/api/v1/links \
-H "Authorization: Bearer $SHORTN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/spring",
"title": "Spring campaign",
"workspace_public_id": "8c0f6b52-4d0e-4a71-9a3e-2f6d1c7b5a10"
}'The answer is 201 Created:
{
"public_id": "3f6c1e2a-9b8d-4c7e-a1f0-5d2e3c4b6a71",
"short_url": "https://shtnl.ink/abC12x9",
"short_code": "abC12x9",
"original_url": "https://example.com/spring",
"title": "Spring campaign",
"link_status": "active"
}Share short_url. Keep public_id: the API addresses a link by it, not by its short code.
Without workspace_public_id the link goes to your personal workspace.
Create a link lists every option: UTM parameters, tags,
an expiry, a password, targeting and more.
4. Read its clicks
Open the short link once in a browser, then:
curl https://app.shortn.link/api/v1/analytics/links/3f6c1e2a-9b8d-4c7e-a1f0-5d2e3c4b6a71 \
-H "Authorization: Bearer $SHORTN_API_KEY"{
"total_clicks": 1,
"unique_clicks": 1,
"clicks_by_country": {
"Germany": 1
}
}A new click can take a moment to show up; the X-Analytics-As-Of header says how complete
the numbers are (see freshness).
Next steps
- Making requests: pagination, errors, rate limits and retries, before you build on these calls.
- Send conversion events: report the leads and sales your links bring, with the click id.
- SDKs: the same calls from an official library.
- API reference: every endpoint.