ASP (VBScript) API Kit

The following code is a VBScript example of sending a message using XML.

  1. <%@ language="VBScript" %>
  2. <%
  3. Option Explicit
  4. '************************************************************************
    **********
  5. ' Sample SMS API XML Interface example in VBScript/ASP
  6. ' Copyright Mediaburst 2010
  7. '
  8. ' IMPORTANT NOTE:
  9. ' This script is a brief example and should not be used in a live
    environment
  10. ' This example does not include any error checking or error handling,
  11. ' error handling must be added before use in a live environment.
  12. ' This script is provided without warranty and Mediaburst do not offer
  13. ' any support in the use of this example.
  14. '************************************************************************
    **********
  15. ' Variable declaration
  16. Dim httpConn, responseDoc, serverURL, username, password, originator,
    content, clientid
  17. ' XML variables
  18. Dim sendDoc, xmlDecl, msgNode, userNode, passNode, proxyURL
  19. serverURL = "http://sms.message-platform.com/xml/send.aspx"
  20. '************************************************************************
    **********
  21. ' Proxy Server URL - Leave as blank string if not required
  22. ' This is only supported if using MSXML version 6
  23. ' e.g. proxyURL = "http://1.2.3.4:3128"
  24. proxyURL = ""
  25. ' Set your account details here
  26. ' API Account Username
  27. username = "my_user"
  28. ' API Account Password
  29. password = "my_pass"
  30. ' Message originator (from)
  31. originator = "MB_ASP"
  32. ' Message Content
  33. content = "Hello, this is a test message from my ASP script"
  34. ' Client ID / Job ID
  35. clientID = "123456"
  36. ' This array is just for example purposes, normally you would supply
    destination addresses
  37. Dim destAddrs(1)
  38. destAddrs(0) = "441234567890"
  39. destAddrs(1) = "449876543210"
  40. '************************************************************************
    **********
  41. ' Create an XML Document object - Might have to change this depending
    upon version of MSXML installed
  42. ' This will also need changing at line 96 where it creates
    MSXML2.ServerXMLHTTP.6.0
  43. ' Version 2.x use Msxml.DOMDocument
  44. ' Version 3.0 use Msxml2.DOMDocument.3.0
  45. ' Version 4.0 use Msxml2.DOMDocument.4.0
  46. ' Version 6.0 use Msxml2.DOMDocument.6.0
  47. Set sendDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
  48. ' Create an XML declaration at the top of the document
  49. Set xmlDecl = sendDoc.createProcessingInstruction("xml", "version='1.0'")
  50. sendDoc.appendChild xmlDecl
  51. Set msgNode = sendDoc.createElement("Message")
  52. Set sendDoc.documentElement = msgNode
  53. Set userNode = sendDoc.createElement("Username")
  54. Set passNode = sendDoc.createElement("Password")
  55. userNode.nodeTypedValue = username
  56. passNode.nodeTypedValue = password
  57. msgNode.appendChild userNode
  58. msgNode.appendChild passNode
  59. ' Loop round the following section for each SMS you want to send
  60. Dim anAddr ' single destination address
  61. for each anAddr in destAddrs
  62. ' Create Nodes
  63. Dim smsNode, toNode, contentNode, fromNode, idNode
  64. Set smsNode = sendDoc.createElement("SMS")
  65. Set toNode = sendDoc.createElement("To")
  66. Set contentNode = sendDoc.createElement("Content")
  67. Set fromNode = sendDoc.createElement("From")
  68. Set idNode = sendDoc.createElement("ClientID")
  69. ' Assign values
  70. toNode.nodeTypedValue = anAddr
  71. contentNode.nodeTypedValue = content
  72. fromNode.nodeTypedValue = originator
  73. idNode.nodeTypedValue = clientID
  74. ' Append nodes to SMS node
  75. smsNode.appendChild toNode
  76. smsNode.appendChild contentNode
  77. smsNode.appendChild fromNode
  78. smsNode.appendChild idNode
  79. ' Append SMS node to main document
  80. msgNode.appendChild smsNode
  81. next
  82. ' End of loop
  83. ' Create HTTP Connection Object
  84. Set httpConn = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
  85. ' Optionally setup a proxy server
  86. If (proxyURL <> "") Then
  87. httpConn.setProxy 2, proxyURL
  88. End If
  89. ' Open synchronous connection
  90. httpConn.open "POST", serverURL, false
  91. httpConn.setRequestHeader "Content-type","text/xml"
  92. httpConn.Send sendDoc.xml
  93. If(httpConn.status = 200) Then
  94. ' Load the response into an XML DOM Document object
  95. set responseDoc = httpConn.responseXML
  96. Dim respNode, genErrNo, genErrDesc
  97. For each respNode in responseDoc.documentElement.childNodes
  98. Select Case respNode.nodename
  99. Case "ErrNo"
  100. genErrNo = respNode.Text
  101. Case "ErrDesc"
  102. genErrDesc = respNode.Text
  103. Case else
  104. Dim aNode, respTo, respClientID, respMsgID, respErrNo,
    respErrDesc
  105. For each aNode in respNode.childNodes
  106. Select Case aNode.nodename
  107. Case "To"
  108. respTo = aNode.text
  109. Case "ClientID"
  110. respClientID = aNode.Text
  111. Case "MessageID"
  112. respMsgID = aNode.Text
  113. Case "ErrNo"
  114. respErrNo = aNode.Text
  115. Case "ErrDesc"
  116. respErrDesc = aNode.Text
  117. End Select
  118. Next
  119. ' Output the response for testing - Normally this would
    update your database
  120. Response.Write("<p>A Message")
  121. Response.Write("<br>To: " & respTo)
  122. Response.Write("<br>Client ID: " &
    respClientID)
  123. Response.Write("<br>Message ID: " & respMsgID)
  124. If(respErrNo <> "") Then
  125. Response.Write("<br>Error [" & respErrNo
    & "] " & respErrDesc)
  126. End If
  127. Response.Write("</p>")
  128. End Select
  129. Next
  130. If(genErrNo <> "") Then
  131. Response.Write("General Error [" & genErrNo & "] "
    & genErrDesc)
  132. End If
  133. Else
  134. Response.Write("HTTP ErrorStatus Code: " & httpConn.status
    & "Response: " & httpConn.responseText)
  135. End If
  136. %>
<%@ language="VBScript" %>
<%
Option Explicit

'********************************************************************************** ' Sample SMS API XML Interface example in VBScript/ASP ' Copyright Mediaburst 2010 ' ' IMPORTANT NOTE: ' This script is a brief example and should not be used in a live environment ' This example does not include any error checking or error handling, ' error handling must be added before use in a live environment. ' This script is provided without warranty and Mediaburst do not offer ' any support in the use of this example. '**********************************************************************************

' Variable declaration Dim httpConn, responseDoc, serverURL, username, password, originator, content, clientid ' XML variables Dim sendDoc, xmlDecl, msgNode, userNode, passNode, proxyURL

serverURL = "http://sms.message-platform.com/xml/send.aspx"

'********************************************************************************** ' Proxy Server URL - Leave as blank string if not required ' This is only supported if using MSXML version 6 ' e.g. proxyURL = "http://1.2.3.4:3128" proxyURL = ""

' Set your account details here ' API Account Username username = "my_user"

' API Account Password password = "my_pass"

' Message originator (from) originator = "MB_ASP"

' Message Content content = "Hello, this is a test message from my ASP script"

' Client ID / Job ID clientID = "123456"

' This array is just for example purposes, normally you would supply destination addresses Dim destAddrs(1) destAddrs(0) = "441234567890" destAddrs(1) = "449876543210" '**********************************************************************************

' Create an XML Document object - Might have to change this depending upon version of MSXML installed ' This will also need changing at line 96 where it creates MSXML2.ServerXMLHTTP.6.0 ' Version 2.x use Msxml.DOMDocument ' Version 3.0 use Msxml2.DOMDocument.3.0 ' Version 4.0 use Msxml2.DOMDocument.4.0 ' Version 6.0 use Msxml2.DOMDocument.6.0 Set sendDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")

' Create an XML declaration at the top of the document Set xmlDecl = sendDoc.createProcessingInstruction("xml", "version='1.0'") sendDoc.appendChild xmlDecl

Set msgNode = sendDoc.createElement("Message") Set sendDoc.documentElement = msgNode

Set userNode = sendDoc.createElement("Username") Set passNode = sendDoc.createElement("Password")

userNode.nodeTypedValue = username passNode.nodeTypedValue = password msgNode.appendChild userNode msgNode.appendChild passNode

' Loop round the following section for each SMS you want to send Dim anAddr ' single destination address for each anAddr in destAddrs ' Create Nodes Dim smsNode, toNode, contentNode, fromNode, idNode Set smsNode = sendDoc.createElement("SMS") Set toNode = sendDoc.createElement("To") Set contentNode = sendDoc.createElement("Content") Set fromNode = sendDoc.createElement("From") Set idNode = sendDoc.createElement("ClientID") ' Assign values toNode.nodeTypedValue = anAddr contentNode.nodeTypedValue = content fromNode.nodeTypedValue = originator idNode.nodeTypedValue = clientID ' Append nodes to SMS node smsNode.appendChild toNode smsNode.appendChild contentNode smsNode.appendChild fromNode smsNode.appendChild idNode ' Append SMS node to main document msgNode.appendChild smsNode next ' End of loop

' Create HTTP Connection Object Set httpConn = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")

' Optionally setup a proxy server If (proxyURL <> "") Then httpConn.setProxy 2, proxyURL End If

' Open synchronous connection httpConn.open "POST", serverURL, false

httpConn.setRequestHeader "Content-type","text/xml" httpConn.Send sendDoc.xml

If(httpConn.status = 200) Then ' Load the response into an XML DOM Document object set responseDoc = httpConn.responseXML Dim respNode, genErrNo, genErrDesc For each respNode in responseDoc.documentElement.childNodes Select Case respNode.nodename Case "ErrNo" genErrNo = respNode.Text Case "ErrDesc" genErrDesc = respNode.Text Case else Dim aNode, respTo, respClientID, respMsgID, respErrNo, respErrDesc For each aNode in respNode.childNodes Select Case aNode.nodename Case "To" respTo = aNode.text Case "ClientID" respClientID = aNode.Text Case "MessageID" respMsgID = aNode.Text Case "ErrNo" respErrNo = aNode.Text Case "ErrDesc" respErrDesc = aNode.Text End Select Next ' Output the response for testing - Normally this would update your database Response.Write("<p>A Message") Response.Write("<br>To: " & respTo) Response.Write("<br>Client ID: " & respClientID) Response.Write("<br>Message ID: " & respMsgID) If(respErrNo <> "") Then Response.Write("<br>Error [" & respErrNo & "] " & respErrDesc) End If Response.Write("</p>") End Select Next If(genErrNo <> "") Then Response.Write("General Error [" & genErrNo & "] " & genErrDesc) End If Else Response.Write("HTTP ErrorStatus Code: " & httpConn.status & "Response: " & httpConn.responseText) End If %>