Labels

Tuesday, July 19, 2011

Using web-service to send SMS from NAV

Recently I had a task to send SMS notification through the Webservice.
My service provider use following interface protocols.
Request for sending SMS:
Where:
  • login and password are the authentication parameters;
  • id is the internal message ID;
  • recipient is the mobile phone number of the recipient;
  • sender is a sender description;
  • text is a message text.
This request should be posted to a webservice via HTTP or HTTPS.

The response has the following format:
Where 201 is the status code of the message sent.
Status code can be one of the following (only main codes are listed):
  • 100 - message scheduled, delivery is not initiated yet;
  • 102 - message delivered to destination;
  • 2** - error codes: bad message format, recepient and so on.

I have created a special SMS Message table in NAV with the following structure:
I think there is no need to comment every field.
The trigger on inserting a record is following:
HTTP is 'Microsoft XML, v6.0'.XMLHTTP60 automation class. As you could see I realized special functions to save XML request and response for comfortable debugging in temporary windows directory. This lines could be wiped later.
When debugging that interface I was stuck by the fact, that ResponseXML returned zero-size document. This was happen because ContentType in ResponseHeader was text\html (not xml), therefore response could not be parsed by HTTP object. Obviously, I was forced to parse the response by loading document from the ResponseText (string variable).
To send SMS I used simple code below:

Webservice provide method to get delivery status of the posted messages.
Request:
Response:
I've created trigger on SMS Message table to update the status and initiate that trigger by the scheduler job:

2 comments:

Anonymous said...

Hi..Can you please send all the object!
sami.3187@gmail.com

Thanks in Advance

GRIZZLY said...

This code snippet doesn't provide exact solution for you. It should only guide you to realize your needs. It's up to you to develop and improve it. Sorry...