Share Location Information

POST and GET Methods

Overview

Share your business-related location like nearest ATM, or a store from your WhatsApp account using API. To send the location information, you need to add latitude and longitude coordinates as additional parameters to the standard outbound WhatsApp API request.

To send location information

  1. Sign in to KCloud and create your API key.

Refer to the Create an API Key page for steps to create your API key. To view the API Key and the SID, see View API Key and SID.

📘

Note:

After you sign up, your account will be on the trial version. You need to complete the KYC to access all the features of KCloud.

  1. Send the location information

You can use the below API’s for the location information via WhatsApp account

POST

cURL -X POST "https://api.kaleyra.io/v1/<SID>/messages" \
     -H "Content-Type: <CONTENT_TYPE>" \
     -H "api-key:<API_KEY>" \
     -d "to=<TO_NUMBER>" \
     -d "type=<MESSAGE_TYPE>" \
     -d "param_lat=<LATITUDE GEO CO-ORDINATE>" \
     -d "channel=<CHANNEL_NAME>" \
     -d "from=<FROM_NUMBER>" \
     -d "callback_url=<CALLBACK_URL>"
     -d "param_long=<LONGITUDE GEO CO-ORDINATE>" \
     -d "param_name=<RECEIVER NAME>" \
     -d "param_address=<RECEIVER ADDRESS>" \

GET

curl --location --request GET 'https://api.kaleyra.io/v1/<SID>/messages?channel=<CHANNEL_NAME>&to=<TO_NUMBER>&from=<FROM_NUMBER>&type=<MESSAGE_TYPE>&param_lat=<LATITUDE GEO CO-ORDINATE>&param_long=<LONGITUDE GEO CO-ORDINATE>&param_name=<RECEIVER NAME>&param_address=<RECEIVER ADDRESS>' 
--header 'api-key:<API_KEY>'

Ensure that you replace the parameter values with the proper inputs in the above code. The below table has a list of parameters and their information.

Replace

With

Example

Required

SID

Account SID (Security Identifier)

HXXXXXXX071US

Yes

CONTENT_TYPE

The format in which the data is sent.

application/x-www-form-urlencoded

Yes

API_KEY

API Key generated by KCloud.

Ac4XXXXX21f

Yes

TO_NUMBER

A valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format).

  • *Note:** You can add multiple recipients separated by the comma.

+1202XXXXXXX

Yes

MESSAGE_TYPE

Format of the message.

location

Yes

LATITUDE GEO CO-ORDINATE

Latitude coordinate

38.846439

Yes

CHANNEL_NAME

Channel on which the message should be sent.

WhatsApp

Yes

FROM_NUMBER

The WhatsApp business number registered with KCloud from which the message is to be sent. Ensure the number is prefixed with the country code. (E164 format).

+1202XXXXXXX

Yes

CALLBACK_URL

The URL that KCloud should send information to when your number receives a response. This URL can be accessed publicly.

https://webhook.site/89b43b12-b889-4f66-8ebf-3379b4b3345c

Optional

LONGITUDE GEO CO-ORDINATE

Longitude coordinate

-94.547432

Yes

RECEIVER NAME

Name of the receiver who receives the location information

John

Yes

RECEIVER ADDRESS

Address of the receiver

LA

Yes

  1. Below is the response sample of both the GET and POST methods.

{
    "id": "794a85fa-3d92-4ca4-86df-f3459aacd128",
    "type": "location",
    "createdDateTime": "2020-10-06 08:57:22+00:00",
    "totalCount": 1,
    "data": [
        {
            "message_id": "794a85fa-3d92-4ca4-86df-f3459aacd128:0",
            "recipient": "91xxxxxxxxxx"
        }
    ],
    "error": {}
}
📘

Note:

In case of an error, ensure that the parameter values are correct in the above code. Refer to the Error Codes and their Description page for detailed information.