Daniel Ferreira
Developer Advocate
A practical introduction to ShortLink's REST API — creating links, querying analytics, managing workspaces, and handling webhooks in a real integration.
If you're shortening links manually, you're leaving automation on the table. ShortLink's REST API lets you create links, fetch analytics, manage workspaces and receive click events — all programmatically.
Authentication
Generate an API key in Workspace Settings → API Keys. Pass it as a Bearer token in every request: Authorization: Bearer sl_live_xxxxxxxxxxxxxxxx
Creating a Short Link
POST /api/v1/links with a JSON body containing url (required), slug (optional), and utm_* fields (optional). The response includes your short_url and the link id.
Querying Analytics
GET /api/v1/links/{id}/analytics?from=2025-01-01&to=2025-12-31 returns click_count, countries array, devices breakdown, and referrers. Supports pagination.
Webhook Setup
Register a webhook endpoint in your dashboard. ShortLink posts a JSON payload to your URL for every click event — includes timestamp, country, device, browser, and the link id that was clicked.
Validate incoming webhooks by checking the X-ShortLink-Signature header against an HMAC-SHA256 of the payload body using your webhook secret.
Common Automation Patterns
- E-commerce: create a unique tracked link for each product in a new collection
- Email: auto-shorten all links in outgoing emails via a pre-send webhook
- Reporting: pull click data into a Google Sheet via a daily cron job
- Zapier: trigger on new link creation and post to Slack with the short URL
About the author
Daniel Ferreira
Developer Advocate at ShortLink
Writing about growth, product, and the future of link intelligence at ShortLink.