Enterprise SMS APIDocument
Enterprise SMS APIDocument
Enterprise SMS APIDocument
1
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
2
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Contents
1. Overview .............................................................................................................................................. 5
2. The API End Point .............................................................................................................................. 5
2.1. User Authentication Scheme .................................................................................................... 5
2.2. Data Encryption .......................................................................................................................... 5
3. Pre Start Checklist ............................................................................................................................. 5
4. Message Length Chart ...................................................................................................................... 6
5. Sending a Single Message ............................................................................................................... 8
5.1. Parameters .................................................................................................................................. 8
5.2. Encoding the Message ............................................................................................................ 10
5.3. Success Response .................................................................................................................. 10
5.4. Failure Response ..................................................................................................................... 10
5.5. API Error codes ........................................................................................................................ 11
5.6. Examples ................................................................................................................................... 12
5.7. Comma / Pipe separated API Call ......................................................................................... 12
5.8. Encrypted payload in Send Message API call ..................................................................... 13
6. Uploading a File ................................................................................................................................ 16
6.1. Uploading a file with HTTPS request .................................................................................... 16
6.2. Success Response .................................................................................................................. 17
6.3. Error Response......................................................................................................................... 17
6.4. Customized File Upload .......................................................................................................... 18
6.5. Scheduling Feature in file upload .......................................................................................... 19
7. API Features ..................................................................................................................................... 19
7.1. International Messaging .......................................................................................................... 19
7.2. Link Tracking ............................................................................................................................. 19
7.3. Zone Info API ............................................................................................................................ 20
7.4. Two Factor Authentication (2FA) API.................................................................................... 21
7.5. Realtime Delivery Reports ...................................................................................................... 25
8. Setting a Response SMS to Marketing Call-to-Actions .............................................................. 29
8.1. Keyword Response URL ......................................................................................................... 29
8.2 Missed Call Response URL .................................................................................................... 31
3
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
4
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
1. Overview
This User Manual provides specifications of the API for the automated sending of SMS via the Internet through
HTTPS mode. This guide is intended for the developers and clients alike who plan to integrate their systems with
Bulk SMS service of Gupshup.
Please use this URL for all API methods. Our API has been designed to allow you to access an SSL Enabled
connection for added security i.e. supports Hypertext Transfer Protocol over Secure Socket Layer (HTTPS)
protocol.
You must use this key to encrypt API parameter values when sending the API request. Once the request is received
by Gupshup, the payload is decrypted by Gupshup and sent ahead to the operator.
User name & password. If you don’t have an account you can create one at
https://enterprise.smsgupshup.com
URL encoding of your message, password etc.
For any queries our support is available for you at 022 42006799 or email us at enterprise-
[email protected]
5
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
6
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
31 SMS 4743-characters
32 SMS 4896-characters
33 SMS 5049-characters
34 SMS 5202-characters
35 SMS 5355-characters
36 SMS 5508-characters
37 SMS 5661-characters
38 SMS 5814-characters
39 SMS 5967-characters
40 SMS 6120-characters
41 SMS 6273-characters
42 SMS 6426-characters
43 SMS 6579-characters
44 SMS 6732-characters
45 SMS 6885-characters
46 SMS 7038-characters
47 SMS 7191-characters
48 SMS 7344-characters
49 SMS 7497-characters
50 SMS 7650-characters
51 SMS 7803-characters
52 SMS 7956-characters
53 SMS 8000-characters
7
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to=9199xxxxxxxx&msg=Welco
me%20to%20SMS%20GupShup%20API&msg_type=TEXT&userid=XXXXXX&auth_scheme=plain&password=pass
word&v=1.1&format=text
5.1. Parameters
Account number provided by The number must be in pure numeric format with no special
userid
Enterprise SMS GupShup characters.
8
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
UrlEncoded string of UTF-8 The message that needs to be sent. It can contain
msg
characters alphanumeric & special characters
Optional
You can input any text in this parameter and the same value will be
extra Alphanumeric characters forwarded in callback url. 50 alphanumeric characters are allowed
for this parameter.
Numeric characters provided by The Entity ID registered with the DLT platform. Every entity has to
principalEntityId
operators DLT Portal register themselves on operators DLT portal to send messages.
The Template ID registered with the DLT platform for the Entity ID.
Numeric characters provided by
dltTemplateId Each entity has to register templates to send messages to their
operators DLT Portal
registered customers.
Post DLT implementation, you need to pass principalEntityId and dltTemplateId in the API request.
In case you do not want to make any changes in your API call you can share above data (principalEntityId
and dltTemplateId) offline with us i.e. contact your sales manager/Account manager or send an email to our support
team at [email protected]. We will match the data which will be uploaded offline at our end and
sent to operators for delivery with correct principalEntityId and dltTemplateId.
9
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
The message text should be UrlEncoded. The message should be UrlEncoded (also known as percent encoding)
string of UTF-8 characters.
Original text:
Hi Amar!
Happy Diwali to you
Regards,
[email protected]
Encoded text:
Hi%20Amar%21%0AHappy%20Diwali%20to%20you%0ARegards%2C%0Ank%40w.com
Successful execution of the request will generate an HTTP 200 response. The response to any request is a string
of tokens separated by pipe symbol (|).
This indicates that the message request has been successfully accepted for mobile number 919812345678
under a Unique Identifier ‘728014710863298817-1234567890’. The identifier string is unique for each
recipient number and is auto generated at the time of message submission. First number is the transaction
ID and second one is message ID.
10
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
100 An unknown exception has occurred. Please retry the request after some time.
104 This user with number is currently disabled. Please contact support for further details.
110 Only preconfigured masks are allowed. The mask is not in the list of your preconfigured masks.
115 The file type parameter does not match with the uploaded file extension
124 Validity of your SMS pack has expired on. You are not allowed to send messages now.
128 The first row of the file should contain headers. Please see the sample file for details.
The "INTERNATIONAL_PHONE" service is disabled for you. Kindly get the service enabled before
175
using this action
183 Cannot process the request before your working start hour.
Your post request is exactly same as previous and hence has been rejected. If you still want to post
223
please call Customer Delight at 022 42006799
11
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
5.6. Examples
Here are examples for the 2 types of message types. You can replace the highlighted text with your credentials and
sent the messages.
1. Text
https://enterprise.smsgupshup.com/GatewayAPI/rest?msg= Hi%20Test%20Message
&v=1.1&userid=XXXXXXXXX&password=XXXXX&send_to=9XXXXXXXXX&msg_type=text&method=sendMessage
Response: success|919899999999|660362025761505631-520576818555598760
2. Unicode
https://enterprise.smsgupshup.com/GatewayAPI/rest?msg=%E0%A4%8F%E0%A4%B8%20%E0%A4%8F%E0%A
4%AE%20%E0%A4%8F%E0%A4%B8%20%E0%A4%97%E0%A4%AA%E0%A4%B6%E0%A4%AA&v=1.1&useri
d=XXXXXXXXX&password=XXXXX&send_to=9XXXXXXXXX&msg_type=Unicode_Text&method=sendMessage
Received on phone: (copy paste into your browser if you can’t see this)
12
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to=9199xxxxxxxx,9198xxxxxxx
xx,9199xxxxxxxx&msg=Welcome%20to%20SMS%20GupShup%20API&msg_type=TEXT&userid=XXXXXXXX&aut
h_scheme=plain&password=password&v=1.1&format=text
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to=9199xxxxxxxx|9198xxxxxxx
xx|9199xxxxxxxx&msg=Welcome%20to%20SMS%20GupShup%20API
&msg_type=TEXT&userid=XXXXXXX&auth_scheme=plain&password=password&v=1.1&format=text
Note: Maximum 1000 numbers can be passed (Comma/Pipe separated) in a single API call.
A sample request with encrypted data in the payload looks like this. (See sample code in 9)
https://enterprise.smsgupshup.com/GatewayAPI/rest?userid=XXXXXXXXX&encrdata=Dl77gZZ1yQlkvnJKHFWdr5k
Bm0sdDQxFWDGT0C0-S17y_-AWolWkJ-
DxYxJ4SV7ZWjXemxmEuPZgvg3x1mXclMDv04vI1PrycitcjNd5YLJxvXTZ8ypJcP1YFFJd-
zvhYCOAy_TODeap9htSeJ3QEeREU0A3jVI1UfDTdJnFMV5vEfm11JlNJQeojuOK3BO3oPv23pJ64WmNCcUN9Fr
UIJNYBIIgE84ZGyF1XvR2RAR7yGxqgUgnGVs5u1M74MSpy6ftYjtLI4OVPFP4VdI
where
encrdata={{method=SendMessage&send_to=919XXXXXXXXX&msg=
This%20is%20a%20test%20message&msg_type=TEXT&auth_scheme=plain&password=password&v=1.1&format=
text}}
Note : Output of encrdata will be different every time as the IV(Initialization Vector) value will be unique for every
request.
13
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Please note that “userid” parameter is mandatory and its value is to be sent in unencrypted format. All the other
parameters must be sent in encrypted format using AES 256 encryption and base64 encoded using the key.
You must use the key generated for your enterprise account to encrypt API parameter values when sending the API
request. Once the request is received by Gupshup, the payload is decrypted by Gupshup and sent ahead to the
operator. Refer 2.2 section.
1) Form a querystring using rest of the API parameters and its values
Querystring: method=SendMessage&send_to=919XXXXXXXXX&msg=
This%20is%20a%20test%20message&msg_type=TEXT&auth_scheme=plain&password=password&v=1.1
&format=text
Parameters and Values to be passed in encrdata. Please note both the parameters and its values should be
encrypted.
14
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Optional
15
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
6. Uploading a File
The file upload API is designed to enable a user to upload a file through which the user can send different
messages to large set of numbers in single authentication. The API supports uploading files of the following
formats:
1. XLS file
2. CSV file
3. ZIP file containing either an XLS or a CSV file
The first row in each file contains the headers for which the values are provided in the following rows. All the
headers are case sensitive in both .csv and .xls files
Ensure the following guidelines are followed when using a CSV file. To know more about CSV files, please see this:
http://en.wikipedia.org/wiki/Comma-separated_values
16
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
filetype .xls, .csv or zip It specifies the format of the file being uploaded
Indicates the type of the message to be sent. Message can be either text,
Text, Unicode_text, or Unicode_Text (non-English) or flash. Currently, a Flash message can be sent
msg_type
flash, binary only on GSM phones and the maximum length of a flash message is 160
characters.
Parameter
Value Description
(optional)
It is a pure number and needs to be specified if the message is being sent to a
port Port Number
port
Sender can specify a particular time for sending the message. Accepted
timestamp formats are
URL encoded
1. yyyy-MM-dd HH:mm:ss (2008-11-21 23:12:32 or 2008-3-4 2:44:23)
timestamp timestamp in the given
2.MM/dd/yy HH:mm:ss (11/21/08 23:12:32 or 3/4/08 2:44:33)
format
3.MM/dd/yy hh:mm:ss a (11/21/08 11:12:32 PM or 3/4/08 2:44:33 AM)
4. MM/dd/yy hh:mm a (11/21/08 11:12 PM or 3/4/08 2:44 AM)
Your file is being processed. Transaction id 3374138381907707211. Please refer upload history below for final
status.
Final status can be checked on Enterprise panel (enterprise.smsgupshup.com) under SMS Bulk Upload
History.
For the transaction id : 3374138381907707211, 10 entries were successfully uploaded and 0 entries failed.
Duplicate entries found were: 0
When a request is formed properly and if all the entries from the input file fail, then the following response is
generated. This status can be checked in enterprise panel (enterprise.smsgupshup.com) under SMS Bulk
Upload History.
17
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Note: If the message text is same for all the customers then the message header can be ignored in the below sample
excel file. However the message along with the variable fields needs to be clearly indicated in the API parameter.
18
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Sender can specify a particular time for sending the message. Timestamps column can be added in the file. Formats
are as follows:
7. API Features
For international messages, user needs to append 00 before the country code and mobile number.
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to=0044079xxxxxxxx&msg=W
elcome%20to%20SMS%20GupShup%20API&msg_type=TEXT&userid=XXXXXXXXX&auth_scheme=plain&passw
ord=password&v=1.1&format=text
Link Tracking is a powerful feature that delivers meaningful insights about customer behavior based on how, where
and when customers interact with unique links embedded in SMS campaigns.
Link Tracking API will automatically detect the long URL in the message text (based on prefixes like http:, https:,
www) and shorten the long URL. The Long URL is shortened into a URL which is 28 characters long that can
uniquely track the URL click at a recipient level.
19
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to=9198xxxxxxxx&msg=It%27
s%20working%20www.gupshup.io&msg_type=TEXT&userid=XXXXXXXX&auth_scheme=plain&password=passwor
d&v=1.1&format=text&linkTrakingEnabled=TRUE
Response message:
Zone Info API allows a user to fetch Number Info i.e (Carrier, Circle) information for a given number via API. This API
will help customers to get NumberInfo on a real-time basis.
https://enterprise.smsgupshup.com/GatewayAPI/rest?method=GET_MOBILE_NUMBER_INFO&
userid=XXXXXXXX&password=password&format=json&mobileNumber=919XXXXXXXXX&v=1.1&auth_scheme=PL
AIN
Response message:
{
"response": {
"id": "3503979002041402733",
"phone": "XXXXXXXXX",
"details": "",
"status": "success"
},
"data": {
"location": "Gajwel, Andhra Pradesh",
"carrier": "Airtel",
"mobileNumber": "919XXXXXXXX“
}
}
Note: NumberInfo API does not reflect MNP data for the number i.e. it is possible the number has been ported to a
different operator/carrier and circle, but only the original operator / circle is returned.
20
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Two Factor Authentication, also known as 2FA, is the dynamic generation of a numeric/alphanumeric/alphabetical
code that authenticates the user for a single transaction or session. The code or one-time password (OTP) can be
sent to the customer via SMS.
User name & password. If you don’t have an account you can create one at
https://enterprise.smsgupshup.com
For 2FA Account configuration please share below details with support team (enterprise-
[email protected])
Parameters Description
Number of seconds an enterprise user has to wait before the user can resend
Otp Retry in Seconds
OTP
https://enterprise.smsgupshup.com/GatewayAPI/rest?userid=XXXXXXXX&password=XXXXX&method=
TWO_FACTOR_AUTH&v=1.1&phone_no=919XXXXXXXXXX&msg=
Your%20OTP%20code%20is%20%25code%25&format=text&otpCodeLength=4&otpCodeType=NUMERIC
Response Message:
https://enterprise.smsgupshup.com/GatewayAPI/rest?userid=XXXXXXX&password=XXXXXX&
method=TWO_FACTOR_AUTH&v=1.1&phone_no=919XXXXXXXXX& otp_code=1564
21
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Response Message:
Parameters:
The API verifies OTP if given otherwise sends OTP (This is the only
otp_code OTP to be verified
difference between Send OTP and Verify OTP)
Error Codes:
22
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
308 You are re-trying too early. Please wait for some time.
A sample request for “Generate and Send OTP + Verify OTP API” with encrypted data in the API payload looks like
this. (See sample code in 9)
https://enterprise.smsgupshup.com/GatewayAPI/rest?userid=xxxxxxxx&encrdata=
VEYcNxNQQcZ0t6VcfxZwzTpeTmBb0UKPYORWA1_VEIaGWrg7zS6aOdUYvmXCpOZbyGs2w9xKA_c43r0OnrL3KHUgUr
vIY1_5e-Om8y5zoWyCaWbV2OKFpa5yZQe0GQrm8PZyBJ-YIDgE7qswrrPj005nZZyFiCtDP-
50UDnaeg6RTVKV748lkURa1RDcs3lMkh3n5UsaNM5TU_lhkC0yreyuuNu8mlRQmNFDMUMWOfvNvhLL_H4
where
encrdata=
{{password=XXXXX&method=TWO_FACTOR_AUTH&v=1.1&phone_no=919XXXXXXXXX&msg=Your%20OTP%20code%
20is%20%25code%25&format=text&otpCodeLength=4&otpCodeType=NUMERIC}}
https://enterprise.smsgupshup.com/GatewayAPI/rest?userid=xxxxxxxx&encrdata=
2qrYFF2dZpT1kLC9iFlfv2mdJgbtUntUuXtRj_Yz5-tVw3JDUNgvGIBHZF-
QMtJjNsMQwGEV6WZ3uFQPGdGYeVV43Ah3u82BVGO8naTea_Dbw1WbDd-cwc1uoGN8ip14suC6fEOJE2oz7Gy0
where
encrdata= {{password=XXXXXX&method=TWO_FACTOR_AUTH&v=1.1&phone_no=919XXXXXXXXX&otp_code=1564}}
Note : Output of encrdata will be different every time as the IV(Initialization Vector) value will be unique for every
request.
Please note that “userid” parameter is mandatory and its value is to be sent in unencrypted format. All the other
parameters must be sent in encrypted format using AES 256 encryption and base64 encoded using the key.
You must use the key generated for your enterprise account to encrypt API parameter values when sending the API
request. Once the request is received by Gupshup, the payload is decrypted by Gupshup and sent ahead to the
operator. Refer 2.2 section.
23
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
1) Form a querystring using the rest of API parameters and its values
Ex:password=XXXXX&method=TWO_FACTOR_AUTH&v=1.1&phone_no=919XXXXXXXXX&msg=Y
our%20OTP%20code%20is%20%25code%25&format=text&otpCodeLength=4&otpCodeType=NUME
RIC
3) Output of AES Encryption (256 bit) should be encoded using base 64 Urlsafe.
Parameter Description
Specify the user id provided by Gupshup. This must be sent in plaintext (unencrypted). The number
userid
must be in pure numeric format with no special characters.
encrdata Encrypted parameter and values to be sent in query parameters / payload.
Parameters and Values to be passed in encrdata. Please note both the parameter and its value should be
encrypted.
Specific format for API response message. Parameter and its value
format TEXT, XML, JSON must be sent in encrypted format .Encrypted string should be URL
encoded before sending.
This is the length of OTP. It must be a positive integer less than or
otpCodeLength Numeric equals to 10. Parameter and its value must be sent in encrypted
format .Encrypted string should be URL encoded before sending.
This parameter specifies a type of OTP. 3 values are permitted
NUMERIC, NUMERIC(only numbers), ALPHABETIC(only alphabets),
otpCodeType ALPHABETIC or ALPHANUMERIC(mix of numbers and alphabets). Parameter and its
ALPHANUMERIC value must be sent in encrypted format .Encrypted string should be
URL encoded before sending.
The API verifies OTP if given otherwise sends OTP (This is the only
difference between Send OTP and Verify OTP Parameter and its
otp_code OTP to be verified
value must be sent in encrypted format .Encrypted string should be
URL encoded before sending.
Get Request:
You can set a callback URL for each group and APIs to receive real time delivery reports.
1. Log in on https://enterprise.smsgupshup.com
2. Click on Settings in the menu bar
3. Under Advanced Account Settings you can see Realtime Delivery URL
Let's say you have given www.example.com/RealTimeDLR/readurl as the callback URL, the format of the URL
called by GupShup is as follows:
http://example.com/RealTimeDLR/readurl?externalId=%0&deliveredTS=%1&status=%2&cause=%3&phoneNo=%4
&errCode=%6& noOfFrags=%7&mask=%8
25
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Post Request:
HTTP POST request contains a JSON array of one or more events to the call back URL. Maximum 20 events will
be sent in a batch to the callback URL.
The below shows a JSON array with two event objects. You will receive maximum 20 such events in a batch.
[response=
"externalId": 3562707498794989059-328736121207676738,
"eventType": “DELIVERED",
"eventTs": 1526347800000,
"destAddr”: 919892488888,
“srcAddr”: TESTIN,
“cause”: ”SUCCESS”,
“errCode”: 000,
“channel”: “SMS,
“noOfFrags”:1
},
"externalId": 3798318073013708082-252169030017029882,
"eventType": “FAILED",
"eventTs": 1526347800000,
"destAddr”: 91989237777,
“srcAddr”: ABCDEF,
26
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
“cause”: ” UNKNOWN_SUBSCRIBER”,
“errCode”: 003,
“channel”: “SMS”,
“noOfFrags”:1
]]
27
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Cause Explanation:
ABSENT_SUBSCRIBER: When the service provider fails to reach the member/subscriber, this
value is passed
UNKNOWN_SUBSCRIBER: Unknown/invalid number
BLOCKED_MASK: Mask is blocked by SMS GupShup
SYSTEM_FAILURE: Failure due to a problem in the Operator’s systems (Originating or
Destination Operator)
CALL_BARRED: Subscriber has some kind of call barring active on the number due to which
messages from unknown sources are blocked.
SERVICE_DOWN: Operator service is temporarily is down.
OTHER: Message that are sent but could not be delivered for reasons that don’t fall under any
mentioned category
DND_FAIL: Number is either in DND or Blocked due to being in DND or a complaint.
DND_TIMEOUT: Latest DND status is not available in time for the message to be sent. (Max 1
day)
MSG_DOES_NOT_MATCH_TEMPLATE: Template passed in the message content does not match
with dltTemplateId uploaded offline in the system.
OUTSIDE_WORKING_HOUR: Message sending is outside mentioned working hours
We will call the URL provide by you with above mentioned parameters as we receive delivery reports from the
service provider.
28
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
If you have set up a SMS keyword on a long code (10-digit VMN) or a short code and want to be able to send a
dynamic Response SMS to the user, you need to set a Keyword Response URL.
Whenever a request is received on the defined keyword, it will be forwarded to the given Response URL, such as
www.example.com. On receiving an incoming message corresponding to a keyword, the GupShup server calls the
following URL:
http://www.example.com?phonecode=%pcode&keyword=%kw&location=%loc&carrier=%car&content=%con&msisd
n=%ph×tamp=%time
The response URL consists details of response such as the sender’s phone number, the time when request was
received, the keyword on which request was received, the additional message with the request, and so on. Thus,
for the keyword Test, phone code 9220092200, and message “Test Nagpur”, the server calls the following URL:
http://www.example.com?phonecode=9220092200&keyword=Test&location=Mumbai&carrier=Vodafone&content=T
estNagpur&msisdn=9812348765×tamp=13082098000
Note: The timestamp shows the epoch time. It has 3 more zeros as it is stored with milliseconds’
significance. View more information on Epoch time at http://www.epochconverter.com/
If you wish to generate a response through the Callback URL, you must ensure that the response conforms to a
specified XML format. If the remote server returns an invalid XML message or does not return an XML message at
all, the first 160 characters of server response are used to compose the message.
29
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
XML Example:
<response>
<message type=“text”>Message 1</message>
<message type=“text”>Message 2</message>
</response>
The following diagram explains the entire flow of the keyword response process.
30
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
http://www.example.com/getresponse.php?msisdn=$msisdn&extension=$extension&causeId=$causeId&hasUserH
ungUp=$hasUserHungUp×tamp=$timestamp&carrier=$carrier&location=$location
3. The response URL consists of details such as msisdn which is sender’s phone number, the time when
request was received, the extension on which miscall was received, the additional hasUserHungUp.
Sample URL:
http://www.example.com/getresponse.php?msisdn=9199XXXXXXXX&extension=61XXXXXX&causeId=274797509
1988275239&hasUserHungUp=false×tamp=1427095786196&carrier=Airtel&location=Mumbai
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
System.out.println(AES.encrypt(queryString));
}
}
<?php
$request =""; //initialise the request variable $param[method]= "sendMessage";
$param[send_to] = "919xxxxxxxxx"; $param[msg] = "Hello"; $param[userid] = "xxxxxxxx"; $param[password] =
"xxxxxxxx"; $param[v] = "1.1";
$param[msg_type] = "TEXT"; //Can be "FLASH”/"UNICODE_TEXT"/”BINARY” $param[auth_scheme] = "PLAIN";
//Have to URL encode the values foreach($param as $key=>$val) {
$request.= $key."=".urlencode($val); //we have to urlencode the values $request.= "&";
//append the ampersand (&) sign after each parameter/value pair
}
$request = substr($request, 0, strlen($request)-1); //remove final (&) sign from the request
$url = "https://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $curl_scraped_page = curl_exec($ch); curl_close($ch);
echo $curl_scraped_page;
?>
32
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
Import java.io.BufferedReader;
Import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date; public class GatewayAPITest {
public static void main(String[] args){ try {
Date mydate = new Date(System.currentTimeMillis());
String data = "";
data += "method=sendMessage";
data += "&userid=xxxxxxxx"; // your loginId data += "&password=" +
URLEncoder.encode("xxxxxx", "UTF-8"); // your password
data += "&msg=" + URLEncoder.encode("GUPSHUP
message" + mydate.toString(), "UTF-8");
data += "&send_to=" +
URLEncoder.encode("9xxxxxxxxx", "UTF-8"); // a valid 10 digit phone no.
data += "&v=1.1" ;
data += "&msg_type=TEXT"; // Can by "FLASH" or
"UNICODE_TEXT" or “BINARY”
data += "&auth_scheme=PLAIN";
URL url = new URL("https://enterprise.smsgupshup.com/GatewayAPI/rest?" + data);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuffer buffer = new StringBuffer(); while ((line = rd.readLine()) != null){
buffer.append(line).append("\n");
}
System.out.println(buffer.toString());
rd.close();
conn.disconnect();
}
catch(Exception e){ e.printStackTrace();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO; namespace GupshupAPI{
class Program{
33
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
static void Main(string[] args){ string result = ""; WebRequest request = null;
HttpWebResponse response = null; try{
String sendToPhoneNumber = "919xxxxxxxxx"; String userid = "xxxxxxxxx";
String passwd = "xxxxx"; String url =
"https://enterprise.smsgupshup.com/GatewayAPI/rest?method=sendMessage&send_to=" + sendToPhoneNumber +
"&msg=hello&userid=" + userid +"&password=" + passwd + "&v=1.1"&msg_type=TEXT&auth_scheme=PLAIN";
request = WebRequest.Create(url);
//in case u work behind proxy, uncomment the commented code and provide correct details
/*WebProxy proxy = new WebProxy("http://proxy:80/",true); proxy.Credentials = new
NetworkCredential("userId","password", "Domain"); request.Proxy = proxy;*/
// Send the 'HttpWebRequest' and wait for response. response = (HttpWebResponse)request.GetResponse(); Stream
stream = response.GetResponseStream();
Encoding ec = System.Text.Encoding.GetEncoding("utf-8"); StreamReader reader = new
System.IO.StreamReader(stream, ec);
result = reader.ReadToEnd(); Console.WriteLine(result);
reader.Close();
stream.Close();
}
catch (Exception exp){ Console.WriteLine(exp.ToString());
}
finally{
if(response != null) response.Close();
}
}
}
}
<html>
<head></head>
<body>
<form name="xlsUploadForm" action="https://enterprise.smsgupshup.com/GatewayAPI/rest" method="post"
enctype="multipart/form-data">
34
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
<input type="text" name="method" id="method" value="xlsUpload" /> <input type="text" name="userid" id="userid"
value=<login-id> /> <input type="text" name="password" id="password" value=<url-
encodedpassword> />
<input type="text" name="v" id="version" value="1.1" /> <input type="text" name="auth_scheme" id="auth_scheme"
value=”PLAIN” />
<input type="file" name="xlsFile" /> <select name="filetype" >
<option value="xls">xls</option> <option value="csv">csv</option> <option value="zip">zip</option>
</select>
<input value="Send Message" type="submit" /> </form>
</body>
</html>
gup.bulk_file_upload("/home/myname/addressbook.csv")
35
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
<?php
/**
* Use a Gupshup Enterprise account to send messages.
* Supports setting time and mask for individual messages.
*
* @author Anshul <[email protected]>
*/
class EnterpriseSender{
public $id;
public $password;
/**
* Mask that would appear on receiver’s phone. For what can appear here,
* contact SMS GupShup Support as the mask needs to be set in the account
* before it can be used here.
* @var String
*/
public $mask;
private $_url = "https://enterprise.smsgupshup.com/GatewayAPI/rest"; private $_messages = array();
public function __construct($id, $password, $mask = NULL) {
$this->id = $id;
$this->password = $password;
$this->mask = $mask;
}
/**
*
* @param String $msisdn MSISDN of the recipient (will include 91)
* @param String $content Message content
* @param String $mask One of the mask as set in the enterprise account
* @param String $time In any acceptable format for PHP. Time Zone assumed to be
IST.
* @return Boolean */
public function addMsg($msisdn, $content, $mask = NULL, $time = "now"){ $message = new stdClass();
$message->msisdn = $msisdn; $message->content = $content;
$fileName = tempnam(sys_get_temp_dir(), 'EnterpriseUpload').'.csv'; $myFile = fopen($fileName, 'w');
fputs($myFile, '"'
.implode('","', array( 'PHONE', 'MESSAGE', 'MASKS', 'TIMESTAMPS'
))
.'"'
."\n"
$message->mask = $mask == NULL ? $this->mask : $mask;
$message->time = new DateTime($time, new DateTimeZone("Asia/Kolkata")); $this->_messages[] = $message;
return TRUE;
}
/**
* Sends the response using file upload API
* @return Boolean
*/
public function sendMsg(){ $rows = array();
foreach ($this->_messages as $message) { $rows[] = array(
$message->msisdn, $message->content, $message->mask,
36
©Gupshup Technology India Pvt. Ltd. 2020
GupShup Enterprise API Help Document
$message->time->format('Y-m-d H:i:s')
);
}
);
foreach ($rows as $row) {
fputcsv($myFile, $row, ',', '"');
}
fclose($myFile); $params = array();
$params['method'] = 'xlsUpload'; $params['userid'] = $this->id; $params['password'] = $this->password;
$params['filetype'] = 'csv'; $params['auth_scheme'] = 'PLAIN'; $params['v'] = '1.1';
$params['xlsFile'] = '@'.realpath($fileName);
$response = self::post($this->_url, $params, TRUE, CURL_HTTP_VERSION_1_0); unlink($fileName);
return preg_match('/^success/', $response);
}
public static function post($url, $params, $multipart = FALSE, $version= CURL_HTTP_VERSION_NONE){
if(function_exists('curl_init')){ $ch = curl_init();
$timeout = 60; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, $version); curl_setopt($ch, CURLOPT_POST, TRUE); if($multipart){
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); }else{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout); $data = curl_exec($ch);
if($data === FALSE){
throw new Exception(curl_errno($ch));
}
curl_close($ch); return $data;
}else{
return FALSE;
}
}
}
?>
$post_fields["password"] = "XXXXX";
$post_fields["auth_scheme"] = "PLAIN";
$post_fields["format"] = "JSON";
curl_setopt_array($curl, array(
CURLOPT_URL => "https://enterprise.smsgupshup.com/GatewayAPI/rest",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_fields
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
auth_scheme: 'PLAIN',
password: 'XXXXX',
format: 'JSON' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
import requests
url = "https://enterprise.smsgupshup.com/GatewayAPI/rest"
payload =
"method=sendMessage&send_to=919820XXXXXX&msg=This%20is%20sample%20test%20message%20from%20
GupShup&msg_type=TEXT&userid=XXXXXX&auth_scheme=PLAIN&password=XXXXX&format=JSON"
response = requests.request("POST", url, data=payload)
print(response.text)
39
©Gupshup Technology India Pvt. Ltd. 2020