Create a URL Shortener
POST Method
The Create URL Shortener API request enables you to create a URL shortener.
Note:Either you have to provide a URL or attachment to compress and generate a short link
API Domain and Value
api_domain | Value |
---|---|
IN pod | api.in.kaleyra.io |
SG Pod | api.kaleyra.io |
EU Pod | api.eu.kaleyra.io |
NA pod | api.na.kaleyra.ai |
Request Format
To create URL shortener, use the /url-shortner endpoint.
curl --location --request POST 'https://<api_domain>/v1/<SID>/url-shortner' \
--header 'api-key: <API-KEY>' \
--form 'url="<URL-SRT>"' \
--form 'advanced="<ADVANCED>"' \
--form 'title="<TITLE>"' \
--form 'callback="<CALLBACK>"' \
--form 'slug="<SLUG>"' \
--form 'format="<FORMAT>"'
To create URL shortener using an attachment, use the /url-shortner endpoint
curl --location --request POST 'https://<api_domain>/v1/<SID>/url-shortner' \
--header 'api-key: <API-KEY>' \
--form 'title="<TITLE>"' \
--form 'attach=@"<ATTACH>"'
Note:Ensure to replace the parameter values with the proper inputs in the above code.
Parameters and Variables
Following is the list of parameters and variables used:
Replace | Variable | Description | Example | Mandatory |
---|---|---|---|---|
| String | Base URL based on region |
| True |
| String | Account SID (Security Identifier). | HXXXXXXX071IN | True |
| Alphanumeric | API key generated from Kaleyra.io account. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | True |
| String | URL to be shortened to a short link. | True (if ATTACH is not specified) | |
| File | Attachment to be compressed to a short link.
| @"/home/yxxxl/Downloads/Sxxxw.dxxo.png | True (if URL is not specified) |
| Number | To track the Recipient mobile numbers who have visited the page. By default, the value will be set to 0. Supported values:
| 1 | False |
| String | A title for your URL shortener. If no title is mentioned, then the URL shortener will not contain any title. | KLR | False |
| String | The encoded URL to receive URL visitor information. | webhook.site | False |
| String | Unique identifier for each Shortened URL. For example, in If not specified, it gets generated automatically with a random three or more unique characters up to ten. | oiks | False |
| String | Output format must be as specified by this variable. If not passed or kept Empty then it will be JSON by default. Supported values:
| xml | False |
Response Format
This section provides you with the success and failure JSON response format for different scenarios. Refer to the below sections for more information:
Sample Success Response
Sample Failure Response
Sample Success Response
The following is a sample success response:
{
"code": "RBC187",
"message": "Details saved successfully",
"data": [{
"status": "OK",
"slug": "about-us",
"id": 21,
"txtly": "https://klr.bz/vab"
}],
"error": {}
}
Sample Failure Response
The following is samples of the failure responses:
The following sample failure response appears when you pass a slug/shorty code that is already present:
{
"code": "RBC124",
"message": "shorty code already exists!",
"data": [],
"error": {
"error": "shorty code already exists!"
}
}
{
"code": "RBC233",
"message": "Url entered is invalid",
"data": [],
"error": {
"error": "Url entered is invalid"
}
}
{
"code": "RBC232",
"message": "Invalid value give for advanced,advanced could be either 1 or 0",
"data": [],
"error": {
"error": "Invalid value give for advanced,advanced could be either 1 or 0"
}
}
{
"code": "RBC216",
"message": "For Slug value Maximum 10 characters allowed",
"data": [],
"error": {
"error": "For Slug value Maximum 10 characters allowed"
}
}
{
"code": "RBC213",
"message": "URL/Attachment is required",
"data": [],
"error": {
"error": "URL/Attachment is required"
}
}
Sample Request
Sample request with URL:
curl --location --request POST 'https://api.in.kaleyra.io/v1/HXXXXXXX071IN/url-shortner' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'url="https://dxxxxd-cxxi.exxxxp.mxxxxxxxx.com/"' \
--form 'advanced="1"' \
--form 'title="KLR"' \
--form 'callback="webhook.site"' \
--form 'slug="about-us"' \
--form 'format="xml"'
Sample request with attachment:
curl --location --request POST 'https://api.in.kaleyra.io/v1/HXXXXXXX071IN/url-shortner' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'title="KLR"' \
--form 'attach=@"/home/yxxxl/Downloads/Sxxxw.dxxo.png"'
Updated 10 days ago