Overview
Using this method, messages can be sent to a single subscriber or multiple subscribers but all subscribers should belong to the same group.
Notes:
A user (APIKey account) can make up to 10 parallel requests or use multiple threads concurrently.
For sending messages, a limit of 100 messages per request is Recommended.
Syntax
C#
1
2
3
4
5
6
7
8
9
|
[OperationContractAttribute()] SBT.API.DataContracts.MessageCenter.WSMessageResponse SendMessage( string securityToken, string message, List<WSRecipient> sendTo, string orgCode, string note, string statusUrl ) |
WSDL
Production: https://ui.solutionsbytext.com/Sbt.App.SetUp/WSServices/MessageWSService.svc?singlewsdl
Staging: https://test.solutionsbytext.com/Sbt.App.SetUp/WSServices/MessageWSService.svc?singlewsdl
Parameters
securityToken
- String[1000](Required) - SecurityToken to authenticate the user
message
- String[160] (Required)- Content of the Message to be sent.
sendTo
- List <WSRecipient> (Required) - Recipient contains collection of sentTo and customfields.
* SendTo - String[20] (Required) -Subscriber number to which the message is to be sent (mobile phone number).
* List <CustomFields> (Optional) - Customfields contains collection of key - value pairs.
orgCode
- String[20] (Required) - Default code of the Group where the subscriber is opted-in
note
- String[500] (Optional) - This is a custom ID which is used to track the message transaction.
statusUrl
- String[200] (Optional) - Status URL that can be used to post message status information to a file.
Return Value
WSMessageResponse
Name | Type | Description |
---|---|---|
Result | bool | True/False whether the call was successful or not. |
ErrorCode | int | For Success/Failure it generates an error number |
Message | string | Message related to the error code. |
TransactionTicket | string | ID created from message; this can be used in the 'Get Message Status' function to check the delivery status of the message. |
Note | string | Custom note entered by user while sending message; this can be used in the GetMessageStatusByNote function to check the delivery status of the message. |
Developer Tips
The SendMessage method includes an optional Note parameter. The Note field enables clients to pass data in conjunction with a message delivery attempt. When sending a message to an array of phone numbers, the note is associated with all messages in the request.
Examples of Note field utilization include:
- Branch location associated with the customer account
- Customer segmentation identifier
- Combinations of data to uniquely identify the messages sent to customers
If a client Status URL is provided, the Note field data is posted to the client's Status URL with each real-time message delivery status update.
When the subscriber replies to the message, the Note field data will be posted to the client's Callback URL (if provided) along with the subscriber's response in real-time as well.
The Note field can be used with the GetMessageStatusByNote method to retrieve the status of sent messages using the Note data.
In addition, the API response when invoking SendMessage() includes a TransactionTicket. The TransactionTicket is unique for that request. The TransactionTicket issued for the request can be used with the GetMessageStatus method to retrieve the status of sent messages using the TransactionTicket.
Examples
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
MessageClient messageResult = new MessageClient( "MessageWSServiceHttpEndpoint" ); string securityToken = txtToken.Text; string message = txtMessage.Text; //Create custom fields List<CustomField> customFields = new List<CustomField>(); CustomField customField = new CustomField(); customField.Key = txtKey.Text; customField.Value = txtValue.Text; customFields.Add(customField); //Create recipients List<WSRecipient> recipients = new List<WSRecipient>(); WSRecipient recipient = new WSRecipient(); recipient.SendTo = txtMobile.Text; recipient.CustomFields = customFields.ToArray(); recipients.Add(recipient); string orgCode = txtOrgCode.Text; string note = txtNote.Text; string statusUrl = txtStatusURL.Text; WSMessageResponse wSMessageResponse = messageResult.SendMessage(securityToken, message, recipients.ToArray(), orgCode, note, statusUrl); //process response if (!wSMessageResponse.Result) { //handle error lblError.Text = wSMessageResponse.Message; } else { //handle success lblError.Text = wSMessageResponse.Message; } |
SOAP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
Soap Request < soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser = "http://SBTService/ServiceContracts/" xmlns:dat = "http://SBTAPIService/DataContract/" xmlns:ser1 = "http://schemas.microsoft.com/2003/10/Serialization/" > < soapenv:Header /> < soapenv:Body > < ser:SendMessage > <!--Required:--> < ser:securityToken >Security token</ ser:securityToken > <!--Required:--> < ser:message >Message content</ ser:message > <!--Required:--> < ser:sendTo > <!--Zero or more repetitions:--> < dat:WSRecipient > <!--Required:--> < dat:SendTo >Mobile Number</ dat:SendTo > <!--Optional:--> < dat:CustomFields > <!--Zero or more repetitions:--> < dat:CustomField > <!--Optional:--> < dat:Key >test key</ dat:Key > <!--Optional:--> < dat:Value >test value</ dat:Value > </ dat:CustomField > </ dat:CustomFields > </ dat:WSRecipient > </ ser:sendTo > <!--Required:--> < ser:orgCode >Group Org code</ ser:orgCode > <!--Optional:--> < ser:note >test custom note</ ser:note > <!--Optional:--> < ser:statusUrl >Status URL</ ser:statusUrl > </ ser:SendMessage > </ soapenv:Body > </ soapenv:Envelope > Soap Response < s:Envelope xmlns:s = "http://schemas.xmlsoap.org/soap/envelope/" > < s:Body > < SendMessageResponse xmlns = "http://SBTService/ServiceContracts/" > < SendMessageResult z:Id = "i1" xmlns:a = "http://SBTAPIService/DataContract/" xmlns:i = "http://www.w3.org/2001/XMLSchema-instance" xmlns:z = "http://schemas.microsoft.com/2003/10/Serialization/" > < a:Result >true</ a:Result > < a:ErrorCode >1281</ a:ErrorCode > < a:Message >Message queued successfully</ a:Message > < a:TransactionTicket >Transaction ticket for tracking</ a:TransactionTicket > < a:note >Custom note field</ a:note > </ SendMessageResult > </ SendMessageResponse > </ s:Body > </ s:Envelope > |
JAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
MessageWSService srv = new MessageWSService(); IMessage iMessage = srv.getMessageWSServiceHttpEndpoint1(); WSMessageResponse res = null ; String securityToken = "securityToken" ; String message = "message" ; ArrayOfWSRecipient sendTo = new ArrayOfWSRecipient(); List sendToList = new ArrayList (); WSRecipient recipient = new WSRecipient(); recipient.setSendTo( new JAXBElement( new QName( "http://SBTAPIService/DataContract/" , "SendTo" ), new String( "" ).getClass(), "1233445677889" )); sendToList.add(recipient); sendTo.setWSRecipient(sendToList); String orgCode = "OrgCode" ; String note = "note" ; String statusUrl = "statusUrl" ; try { res = iMessage.sendMessage(securityToken, message, sendTo, orgCode, note, statusUrl); } catch (Throwable e) { e.printStackTrace(); } if (res == null ){ System.out.println( "Erron::" ); return ; } if (res.isResult() == null || !res.isResult()) { //handle error System.out.println( "ErrorCode::" +res.getErrorCode()); System.out.println( "ErrorMessage::" +res.getMessage().getValue()); } else { //handle success System.out.println( "ID::" +res.getId()); System.out.println( "Message::" +res.getMessage().getValue()); } |
PHP (Example 1: Send Single Message)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php $client = new SoapClient( "<< Send Message WSDL URL -->>" ); $param = array ( 'securityToken' => 'securityToken' , 'message' => 'This is a test message [PHP Code]' , 'sendTo' => array ( 'WSRecipient' => array ( 'CustomFields' => array ( 'CustomField' => array ( 'Key' => 'Name' , 'Value' => 'John' , ) ), 'SendTo' => '12345678999' ) ), 'orgCode' => 'orgCode' , 'note' => 'test php code' , 'statusUrl' => 'statusUrl' ); $response = $client ->__soapCall( 'SendMessage' , array ( $param )); echo '<pre?>' ; print_r( $response ); if ( $response ->SendMessageResult->Result){ echo 'Message: ' . $response ->SendMessageResult->Message; echo '<br>' ; echo 'TransactionTicket: ' . $response ->SendMessageResult->TransactionTicket; echo '<br>' ; echo 'Note: ' . $response ->SendMessageResult->note; } else { echo $response ->SendMessageResult->Message; } ?> |
PHP (Example 2: Send Multiple Message with Multiple Variables)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php $client = new SoapClient( "<< Send Message WSDL URL -->>" ); $param = array ( 'securityToken' => 'securityToken' , 'message' => 'This is a test message [PHP Code] - from {FromName} to {ToName}' , 'sendTo' => array ( 'WSRecipient' => array ( array ( 'CustomFields' => array ( 'CustomField' => array ( array ( 'Key' => 'FromName' , 'Value' => 'SBT User1' ), array ( 'Key' => 'ToName' , 'Value' => 'John' ) ) ), 'SendTo' => '12312312345' ), array ( 'CustomFields' => array ( 'CustomField' => array ( array ( 'Key' => 'FromName' , 'Value' => 'SBT User1' ), array ( 'Key' => 'ToName' , 'Value' => 'Albert' ) ) ), 'SendTo' => '12341234123' ) ) ), 'orgCode' => 'orgCode' , 'note' => 'test php code' , 'statusUrl' => 'statusUrl' ' ); $response = $client ->__soapCall( 'SendMessage' , array ( $param )); echo '<pre?>' ; print_r( $response ); if ( $response ->SendMessageResult->Result){ echo 'Message: ' . $response ->SendMessageResult->Message; echo '<br>' ; echo 'TransactionTicket: ' . $response ->SendMessageResult->TransactionTicket; echo '<br>' ; echo 'Note: ' . $response ->SendMessageResult->note; } else { echo $response ->SendMessageResult->Message; } ?> |
REST
Method: POST
URL: https://ui.solutionsbytext.com/SBT.App.SetUp/RSServices/MessageRSService.svc/SendMessage
JSON Request:
1
2
3
4
5
6
7
|
{"securityToken":"Security Token", "message":"Test message from {CustomVariable1} REST { CustomVariable2}", "sendTo":[{"SendTo":"Phone1","CustomFields":[{"Key":" CustomVariable1","Value":"value1"},{"Key":" CustomVariable2","Value":"value2"}]},{"SendTo":"Phone2","CustomFields":[{"Key":" CustomVariable1","Value":"value1"},{"Key":" CustomVariable2","Value":"value2"}]}], "orgCode":"Default Org. Code", "note":"Custom Note", "statusUrl":"Status URL" } |
Response:
1
2
3
4
5
6
7
8
9
|
The response will be in JSON format like below: {" SendMessageResult": { "Result": true, "ErrorCode": 1281, "Message": " Message sent successfully", "TransactionTicket": "AA13J-0618V-15389-174L0", "Note": " Some Notes", }} |