I have been scoping out a recent project which requires an SMS message to be sent from ServiceNow, I want to do this from a script rather than a standard notification with SMS enabled, so I decided to use an Outbound REST message to achieve this. First of all I wanted to craft a working REST message to fire from a background script- just to prove the concept will work before I go ahead with the rest of the solution.

I decided to use the Text App as a provider because they have a free developer account with 20 free text messages to play with.

I then read up on the latest REST Message API (V2) ServiceNow offer, in order to understand how to craft the call and how to log errors returned from the endpoint.

To know what methods I could use to craft my message I also used the Text App development tools website, which is quite detailed.

Here is the code I have used below, as you can see you are able to set a from address or number, the message body and also the data type by setting parameters Text App specify.

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
var requestBody;
var responseBody;
var qstring;
var sm;
try {
sm = new sn_ws.RESTMessageV2();
sm.setHttpMethod("post");
sm.setEndpoint('http://www.textapp.net/webservice/httpservice.aspx?');
sm.setQueryParameter('method','sendsms');
sm.setQueryParameter('externalLogin', 'loginhere');
sm.setQueryParameter('body', 'This is a test test message sent from ServiceLater!');
sm.setQueryParameter('characterSetID', '2');
sm.setQueryParameter('clientBillingReference', 'ServiceLater test');
sm.setQueryParameter('ClientMessageReference', 'uniqueid1');
sm.setQueryParameter('destinations', '+4477777777777');
sm.setQueryParameter('originator', 'ServiceLater');
sm.setQueryParameter('password', 'passwordhere');
sm.setStringParameter('replyData', '');
sm.setQueryParameter('replyMethodID', '1');
sm.setQueryParameter('returnCSVString', 'false');
sm.setQueryParameter('validity', '1');
response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
}
catch(ex) {
responseBody = ex.getMessage();
status = '500';
}
finally {
requestBody = sm ? sm.getRequestBody():null;
}
gs.info("Request Body: " + requestBody);
gs.info("Response: " + responseBody);
gs.info("HTTP Status: " + status);

Thank you for reading and hopefully this will help someone send an SMS using TextApp from ServiceNow in the near future.

1 Comment

  1. Jayvee

    Really useful post thank you!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *