← Back to start page

txt.lk API Documentation

The txt.lk API lets you create and expand shortened URLs from your own software. txt.lk is a simple, privacy-friendly URL shortener.

Getting Started

1. Request an API Key

To use the txt.lk API, you must first obtain an API key. Send a request to rikard@textalk.se

Once you receive your API key, keep it secure as it is used to authenticate all requests.

Authentication

How to Authenticate

All API requests require the Authorization header containing your API key. Without a valid API key, the API will return an error.

Authorization: <your_api_key>

Endpoints

1. Shorten a URL

Endpoint:

POST https://txt.lk/api/index.php?endpoint=shorten

Description:

Creates a shortened URL for a given original URL. Automatically generates QR codes for the shortened URL and stores them in hierarchical directories based on the first three characters of the short key.

Headers:

Key Value
Authorization Your API key
Content-Type application/json

Request Body:

{
  "url": "https://www.youtube.com/watch?v=WDiB4rtp1qw"
}

Response:

On success:

{
  "success": true,
  "short_url": "https://txt.lk/DIG30",
  "qr_codes": {
    "pngUrl": "https://txt.lk/qr/D/I/G/DIG30.png",
    "svgUrl": "https://txt.lk/qr/D/I/G/DIG30.svg"
  }
}

On failure (e.g., missing or invalid URL):

{
  "success": false,
  "error": "Invalid URL."
}

2. Expand a Shortened URL

Endpoint:

GET https://txt.lk/api/index.php?endpoint=expand&key=<short_key>

Description:

Retrieves the original URL for a given shortened URL key.

Headers:

Key Value
Authorization Your API key

Query Parameters:

Parameter Description
key The shortened URL key (e.g., DIG30)

Response:

On success:

{
  "success": true,
  "original_url": "https://www.youtube.com/watch?v=WDiB4rtp1qw"
}

On failure (e.g., key not found):

{
  "success": false,
  "error": "Short key not found."
}

3. Check Usage Count

Endpoint:

GET https://txt.lk/api/index.php?endpoint=usaged&key=<short_key>

Description:

Retrieves the usage count (number of times accessed) for a given shortened URL key.

Headers:

Key Value
Authorization Your API key

Query Parameters:

Parameter Description
key The shortened URL key (e.g., DIG30)

Response:

On success:

{
"success": true,
"usage_count": 42
}

On failure (e.g., key not found):

{
"success": false,
"error": "Short key not found."
}

QR Codes

All shortened URLs automatically receive corresponding QR codes in PNG and SVG formats. These QR codes are stored in hierarchical directories based on the first three characters of the shortened key to optimize file organization and scalability.

1. QR Code URLs

The QR codes are generated at the following URLs:

Replace <first_char>, <second_char>, and <third_char> with the corresponding characters from the shortened URL key.

Example:

For the shortened URL key DIG30:

Error Handling

Every response is JSON. A failed request has "success": false and an "error" message.

HTTP status Message Description
401 Invalid or missing API key. The request did not include a valid API key.
200 Invalid URL. The provided URL is not valid.
200 Short key not found. The specified shortened URL key does not exist.
200 Links to this destination are not allowed. The destination host is on the block list (phishing, suspect sites and other link shorteners).
200 This link has been disabled. Returned by expand when the destination is blocked.
429 Too many links were made with this key. Try again later. The key made too many links in one hour. The Retry-After header shows the wait in seconds.
200 Invalid endpoint or method. The endpoint name or the HTTP method is not supported.

Always check the success field. Only authentication errors use a non-200 HTTP status.

Best Practices

Contact

If you encounter any issues or have questions, please contact Textalk Support: