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.
To use the txt.lk API, you must first obtain an API key. Apply for it here
Once you receive your API key, keep it secure as it is used to authenticate all requests.
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>
POST https://txt.lk/api/index.php?endpoint=shorten
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.
Key | Value |
---|---|
Authorization | Your API key |
Content-Type | application/json |
{
"url": "https://www.youtube.com/watch?v=WDiB4rtp1qw"
}
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."
}
GET https://txt.lk/api/index.php?endpoint=expand&key=<short_key>
Retrieves the original URL for a given shortened URL key.
Key | Value |
---|---|
Authorization | Your API key |
Parameter | Description |
---|---|
key | The shortened URL key (e.g., DIG30 ) |
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."
}
GET https://txt.lk/api/index.php?endpoint=usaged&key=<short_key>
Retrieves the usage count (number of times accessed) for a given shortened URL key.
Key | Value |
---|---|
Authorization | Your API key |
Parameter | Description |
---|---|
key | The shortened URL key (e.g., DIG30 ) |
On success:
{
"success": true,
"usage_count": 42
}
On failure (e.g., key not found):
{
"success": false,
"error": "Short key not found."
}
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.
The QR codes are generated at the following URLs:
https://txt.lk/qr/<first_char>/<second_char>/<third_char>/<short_key>.png
https://txt.lk/qr/<first_char>/<second_char>/<third_char>/<short_key>.svg
Replace <first_char>
, <second_char>
, and <third_char>
with the corresponding characters from the shortened URL key.
For the shortened URL key DIG30
:
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. |
https://txt.lk
to ensure secure communication.If you encounter any issues or have questions, please contact Textalk Support:
Happy shortening! 😊