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
Request Format
To create URL shortener, use the /url-shortner endpoint.
curl --location --request POST '<URL>/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 '<URL>/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 |
---|---|---|---|---|
URL | String | Base URL based on region | <https://api.kaleyra.io> | True |
SID | String | Account SID (Security Identifier). | HXXXXXXX071US | True |
API-KEY | Alphanumeric | API key generated from Kaleyra.io account. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | True |
URL-SRT | String | URL to be shortened to a short link. | https://dxxxxd-cxxi.exxxxp.mxxxxxxxx.com/ | True (if ATTACH is not specified) |
ATTACH | File | Attachment to be compressed to a short link. Note: The attachment must be multipart/form-data. | @"/home/yxxxl/Downloads/Sxxxw.dxxo.png | True (if URL is not specified) |
ADVANCED | Number | To track the Recipient mobile numbers who have visited the page. By default, the value will be set to 0. Supported values: 1 - enable advanced analytics 0 - disable advanced analytics. | 1 | False |
TITLE | String | A title for your URL shortener. If no title is mentioned, then the URL shortener will not contain any title. | KLR | False |
CALLBACK | String | The encoded URL to receive URL visitor information. | webhook.site | False |
SLUG | String | Unique identifier for each Shortened URL. For example, in https://klr.bz/about-us , the URL slug is /about-us If not specified, it gets generated automatically with a random three or more unique characters up to ten. | oiks | False |
FORMAT | 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: JSON or XML. | 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.kaleyra.io/v1/HXXXXXXX071US/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.kaleyra.io/v1/HXXXXXXX071US/url-shortner' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'title="KLR"' \
--form 'attach=@"/home/yxxxl/Downloads/Sxxxw.dxxo.png"'
Updated about 1 year ago