Back to startpage

txt.lk API Documentation

Welcome to the txt.lk API, a simple and privacy-friendly URL shortener service. This API allows you to programmatically create and expand shortened URLs.


Getting Started

1. Request an API Key

To use the txt.lk API, you must first obtain an API key. computer fire Apply for it here Fire again

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

Common Errors:

HTTP Code Message Description
401 Invalid or missing API key. The request did not include a valid API key.
400 Invalid URL. The provided URL is not valid.
404 Short key not found. The specified shortened URL key does not exist.

Best Practices

Contact

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

Happy shortening! 😊

Fire again A really cool rotating skull