Linkly's Link Shortening API

Create, update, and manage links programmatically using Linkly's Link Shortening API.

Related: Analytics API | Webhooks

Before you Begin

Linkly generates API requests in the interface for you to copy & paste into your applications.

This works for link creation and link update.

Save time and let us do the hard work:

  1. See below for link creation API requests.
  2. Copy the requests in their entirety. You can verify they work for you.
  3. Ask ChatGPT or an equivalent to adapt these requests into source code for your application. There is no need to spend time doing a complex integration. Our API is entirely machine-consumable.

OpenAPI 3.0 Spec

You can generate API requests directly from the Linkly user interface.

Linkly's Link Shortening API Builder

Linkly's link shortening API builds API requests automatically based on the contents of the form. You can paste the text given here into any LLM to automatically generate code for your application.

Linkly's API is documented using the OpenAPI standard, which goes beyond what is provided below.

Authorization

You will need:

  • Your API Key
  • Workspace ID

You can get these details from inside Linkly.

  1. Login to Linkly.
  2. Click Settings.
  3. Click API Keys.

To create a link, all you need to do is send a POST request to:

https://app.linklyhq.com/api/v1/link

with the following fields in the body.

The encoding type is x-www-form-urlencoded or application/json.

If you are submitting the Rules field, you must use application/json.

We recommend you use JSON with the Open API spec.

LabelKeyTypeNotes
Account API Keyapi_keyStringRequired
Workspace IDworkspace_idIntegerRequired
Link IDidIntegerRequired if updating existing link
DestinationurlStringRequired
NicknamenameString
NotesnoteString
Retargeting tags (head region)head_tagsStringFor retargeting pixels
Retargeting tags (body region)body_tagsStringFor retargeting pixels
Forward Paramsforward_paramsBoolean
Publishing StatusenabledBoolean
UTM Sourceutm_sourceStringFor UTM tracking
UTM Mediumutm_mediumStringFor UTM tracking
UTM Campaignutm_campaignStringFor UTM tracking
UTM Termutm_termStringFor UTM tracking
UTM Contentutm_contentStringFor UTM tracking
Custom DomaindomainStringRequired if slug is provided. See custom domains
Custom Domain SuffixslugStringIf domain is provided and slug is null, will be auto-generated
Open Graph Titleog_titleStringFor social media previews
Open Graph Descriptionog_descriptionStringFor social media previews
Open Graph Image URLog_imageStringFor social media previews
Meta Pixel IDfb_pixel_idStringFor Meta Pixel
Google Analytics 4 IDga4_tag_idString
Google Tag Manager containergtm_idString
Expiry DateTimeexpiry_datetimeISO8601 DateTime StringFor expiring links
Expiry Destinationexpiry_destinationStringFor expiring links
RulesrulesJSON arrayFor rotators, geo-redirects, and device redirects

Example Request using cURL

The code below illustrates how to make an API request to create a link.

curl -X POST https://app.linklyhq.com/api/v1/link
-H 'cache-control: no-cache'
-d 'api_key=your_secret_key&workspace_id=1&url=http%3A%2F%2Fwww.wikijob.co.uk&name=Test%20Link'

A successful response will return a JSON object representing the link, along with a link id.

{
    "id": 9512,
    "alias": null,
    "url": "https://www.wikijob.co.uk",
    "name": "Test Link",
    "note": null,
    "head_tags": null,
    "body_tags": null,
    "linkify_words": null,
    "enabled": true,
    "cloaking": false,
    "replacements": null,
    "domain": null,
    "slug": null,
    "utm_source": null,
    "utm_medium": null,
    "utm_campaign": null,
    "utm_term": null,
    "utm_content": null,
    "og_title": null,
    "og_description": null,
    "og_image": null,
    "full_url": "https://l.linklyhq.com/l/2TQ",
    "block_bots": false,
    "rules": [],
    "workspace_id": 1448,
    "referer_mode": null,
    "custom_referer": null,
    "click_fraud_mode": null,
    "deleted": false
}

In order to update a link, send the same request you'd use to create the link, but include the field link_id for the link you want to update, as well as the changes.

Creating Rotators via API

In order to create a rotator, submit a field called rules as a JSON array, along with the link payload above. You must use application/json to send JSON arrays.

For example:

[
  {"what": "rotator", "url": "https://www.microsoft.com", "percentage": "50"},
  {"what": "rotator", "url": "https://www.apple.com", "percentage": "50"}
]

Creating Geo-Redirects via API

In order to redirect by country, submit a field called rules as a JSON array, along with the link payload above. You must use application/json encoding to send JSON arrays.

For example:

[
  {"what": "country", "url": "https://www.microsoft.com", "matches": "UK"},
  {"what": "country", "url": "https://www.apple.com", "matches": "US"}
]

The country is the alpha-2 ISO 3166 country code.

Creating Device Redirects via API

In order to redirect by device, submit a field called rules as a JSON array, along with the link payload above.

For example:

[
  {"what": "platform", "url": "https://www.google.com", "matches": "windows"},
  {"what": "platform", "url": "https://www.apple.com", "matches": "ios"}
]

Where the field matches is one of:

  • ios
  • android
  • windows
  • linux
  • mac

Linkly supports the creation/amending of up 1000 links per request.

To do so, submit your API key as part of the request as follows:

https://app.linklyhq.com/api/v1/link?api_key=XXXXXXXXXXX

Then, use the same schema as above for the individual link cases, but wrap the link requests in an array, of the form:

[{link}, {link}]

Here is a complete request that will update two links:

wget --no-check-certificate \
  --method POST \
  --timeout=0 \
  --header 'Content-Type: application/json' \
  --body-data '[
    {
        "workspace_id": "WORKSPACE_ID",
        "url": "https://nature.com",
        "name": "Test",
        "id": LINK_ID
    },
    {
        "workspace_id": "WORKSPACE_ID",
        "url": "https://science.com",
        "id": LINK_ID
    }
]' \
   'https://app.linklyhq.com/api/v1/workspace/WORKSPACE_ID/links?api_key=API_KEY'

This works for both creation and update actions.

Please be aware it can take up to 60 seconds for a large request. If requests take longer than this, they will fail, and you should consider breaking your workload up into smaller chunks.

Rate Limits

The link shortening API is limited to 20 requests/second. Up to 200/requests per second are available on request. You can upload up to 1000 links in a single request.

Track 1000 monthly clicks with all features included.

No credit card required