Skip to main content
The examples below show how to call the Shorturlx API. Each section includes a basic (unauthenticated) request and an authenticated request with a custom slug.

cURL

Basic (no authentication)
curl -X POST "https://www.shorturlx.xyz/api/shorten" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/very-long-url"}'
Authenticated with custom slug
curl -X POST "https://www.shorturlx.xyz/api/shorten" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/very-long-url","customSlug":"my-launch"}'

JavaScript (Node.js)

async function shortenUrl(longUrl) {
  const response = await fetch('https://www.shorturlx.xyz/api/shorten', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ url: longUrl }),
  });

  const data = await response.json();

  if (!response.ok) {
    throw new Error(data.error || 'Failed to shorten URL');
  }

  return data;
}

shortenUrl('https://example.com/very-long-url')
  .then((data) => console.log(data.shortUrl))
  .catch((err) => console.error(err));

Python

import requests

response = requests.post(
    'https://www.shorturlx.xyz/api/shorten',
    headers={'Content-Type': 'application/json'},
    json={'url': 'https://example.com/very-long-url'},
)

if response.status_code != 200:
    raise Exception(response.json().get('error', 'Unknown error'))

print(response.json()['shortUrl'])

iOS Shortcuts

You can automate URL shortening directly from your iPhone or iPad using the Shortcuts app.
1

Add a URL action

In the Shortcuts app, add a URL action and set the value to https://www.shorturlx.xyz/api/shorten.
2

Add a Get Contents of URL action

Add a Get Contents of URL action with the following settings:
  • Method: POST
  • Headers: add Authorization = Bearer YOUR_API_KEY and Content-Type = application/json
  • Request body: JSON — add a key url with the URL you want to shorten (use a Shortcut variable if needed)
3

Extract the short URL

Add a Get Dictionary Value action to extract the shortUrl key from the response.
4

Use the result

Add actions to copy the result to your clipboard, share it, or use it as input in another step.
For terminal usage, see CLI to install the shorturlx-cli npm package and shorten URLs directly from your shell.

Build docs developers (and LLMs) love