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:

ReplaceVariableDescriptionExampleMandatory
URLStringBase URL based on region<https://api.kaleyra.io>True
SIDStringAccount SID (Security Identifier).HXXXXXXX071USTrue
API-KEYAlphanumericAPI key generated from Kaleyra.io account.Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3True
URL-SRTStringURL to be shortened to a short link.https://dxxxxd-cxxi.exxxxp.mxxxxxxxx.com/True (if ATTACH is not specified)
ATTACHFileAttachment to be compressed to a short link.

Note: The attachment must be multipart/form-data.
@"/home/yxxxl/Downloads/Sxxxw.dxxo.pngTrue (if URL is not specified)
ADVANCEDNumberTo 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.
1False
TITLEStringA title for your URL shortener. If no title is mentioned, then the URL shortener will not contain any title.KLRFalse
CALLBACKStringThe encoded URL to receive URL visitor information.webhook.siteFalse
SLUGStringUnique 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.
oiksFalse
FORMATStringOutput 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.
xmlFalse

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"'