chl.li API Documentation

v1

Base URL
https://chl.li/api/v1

Shorten a URL with a POST request

POST
/shorten

To shorten a URL, send a POST request to the following endpoint:

curl -X POST "https://chl.li/api/v1/shorten" \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-api-key" \
  -d '{"url":"https://example.com", "alias": "ex", "expires": "5"}'

Headers

name type required description
Content-Type String Yes Must be application/json
x-api-key String Yes (starting August 1, 2021) More information on API keys and where to get one.

Body

name type required description
url String Yes Must be a valid URL
alias String No Is case sensitive and must be alphanumeric only
expires Number No Sets how many minutes the shortened link should work for

Response

200 (OK)

If you successfully entered a valid body, this endpoint will return an HTTP response with a status code of 200 and a body as below.

{
  "alias": "ex",
  "url": "https://example.com",
  "expires": 1577431840173,
  "created": "2019-12-26T21:08:23.842Z"
}

The expiry property (timestamp) is only returned if the link has been set to expire.

400 (Bad Request)

If you send a URL that is invalid, you don't send an URL at all or the alias you send is invalid / already in use, this endpoint will return an HTTP response with a status code of 400 and a body as below.

[ { "message": "Unable to shorten that link. It is not a valid URL.", "field": "url" } ]

Shorten a URL with a GET request using URL params

GET
/shorten

To shorten a URL using URL parameters, send a GET request to the following endpoint or simply visit it in your browser. The API key is passed using the apikey URL parameter:

curl -H "Accept: application/json" \
  -X GET "https://chl.li/api/v1/shorten?url=https://example.com&alias=ex&apikey=your-api-key"

Parameters

Same as using the POST method.

If you successfully entered a valid query, this endpoint will return an HTTP response with a status code of 200 and a body as below.

{ "url": "chl.li/CklRV" }

Note

Shortening a URL with a GET request will only return the shortened URL, if you need all the data returned, send a request using the POST method mentioned above.

Use the Accept HTTP header to define how the result should be returned (plain text, html or json).

Currently, errors are returned in JSON regardless of the accept header. This will probably change very soon.