Script To Test Sequential Web Services Action

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

maydaymike
Posts: 7
Joined: Fri Jan 21, 2011 12:24 pm

Script To Test Sequential Web Services Action

Post by maydaymike »

Can anyone help with a simple script to do a simple repeat task via webservices?

I have been able to create a mailing using a VB script (createNewMailing) as below that will load an XML file and succesfuly obtain a return (ie mailing ID) but I'd really like to then use this return value straight away to insert into sendMail to trigger the mailing. The parameters will stay fixed for each mailing (ie list / target group etc) - the only variable will be the returned mailingID.

Any ideas? Can I incorporate the full SOAP XML details into the script rather than pulling in a separate file?

Many thanks in advance - it's a bit intense as the code seems to be so near ...!

Code: Select all

Set xmlhttp = CreateObject("Microsoft.XMLHTTP") 

xmlhttp.open "POST" , "http://testdomain.com:8080/emm_webservice", False 
xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded; charset=UTF-8" 
xmlhttp.setRequestHeader "Content-length", "1000" 
xmlhttp.setRequestHeader "Connection", "close" 
xmlhttp.setRequestHeader "soapAction", "newEmailMailing" 

Set oXML = CreateObject("Microsoft.XMLDOM") 
oXML.async = False 
oXML.load("C:\test.xml") 

xmlhttp.send(oXML) 

If(xmlhttp.readyState = 4) then 
XMLResponse = xmlhttp.responseText 
Msgbox XMLResponse 
End If 
If I can incorporate the XML as part of the script and then parse the return I should be able to trigger the next stage.

The external XML file is as follows:

Code: Select all

  <?xml version="1.0" encoding="UTF-8" ?> 
- <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:agnitas-webservice">
  <soapenv:Header /> 
- <soapenv:Body>
- <urn:newEmailMailing soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">testadmin</in0> 
  <in1 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">abc123</in1> 
  <in2 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">TEST_MAIL</in2> 
  <in3 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">WS_TEST_MAIL</in3> 
  <in4 xsi:type="xsd:int">8</in4> 
- <in5 xsi:type="urn:StringArrayType">
- <!-- Zero or more repetitions:
  --> 
  <x xsi:type="xsd:string">2</x> 
  </in5>
  <in6 xsi:type="xsd:int">0</in6> 
  <in7 xsi:type="xsd:int">18</in7> 
  <in8 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Test</in8> 
  <in9 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">0</in9> 
  <in10 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">0</in10> 
  <in11 xsi:type="xsd:int">0</in11> 
  <in12 xsi:type="xsd:int">0</in12> 
  </urn:newEmailMailing>
  </soapenv:Body>
  </soapenv:Envelope>
??
maydaymike
Posts: 7
Joined: Fri Jan 21, 2011 12:24 pm

Re: Script To Test Sequential Web Services Action

Post by maydaymike »

I reckon I have this basically sorted using the following vbs code - it uses a 'master' XML file that contains the 'fixed' mailing data and then a second XML file that is over-written each time a new mailing is created.

The sequence of events is :

a) Script is launced either manually or via Windows Scheduled Tasks at specified time;
b) This creates a mailing based on fixed parameters contained in the test_master.xml file;
c) OpenEMM then returns the mailingID on successful creation which is written into the test_send.xml file;
d) This file is then loaded back into OpenEMM to trigger the mailing;
e) Mailout then returns 'staus' indicator which is displayed in a message box.

The scipt launches very well from Scheduled Tasks - adjusting the delayedMailings.cronExpression as detailed elsewhere on the forum means that scheduled mailings are despatched almist instantly.

Code: Select all

Set xmlhttp = CreateObject("Microsoft.XMLHTTP") 

xmlhttp.open "POST" , "http://testdomain.com:8080/emm_webservice", False 

xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded; charset=UTF-8" 

xmlhttp.setRequestHeader "Content-length", "1000" 

xmlhttp.setRequestHeader "Connection", "close" 

xmlhttp.setRequestHeader "soapAction", "newEmailMailing" 

Set oXML = CreateObject("Microsoft.XMLDOM") 

oXML.async = False 

oXML.load("C:\XML\test_master.xml") 

xmlhttp.send(oXML) 

If(xmlhttp.readyState = 4) then 

Dim oDOM : Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
oDOM.loadXML xmlhttp.responseText
sMailingID = oDOM.selectSingleNode("//ns1:newEmailMailingResponse/newEmailMailingReturn").Text

End If 

Set rXML = CreateObject("Microsoft.XMLDOM") 

rXML.async = False 

rXML.load("C:\XML\temp\test_send.xml") 

Set sXML = CreateObject("Microsoft.XMLDOM")
  
rXML.SelectSingleNode("soapenv:Envelope/soapenv:Body/urn:sendMailing/in2").Text = sMailingID
 
set rdr = CreateObject ( "MSXML2.SAXXMLReader") 
set wrt = CreateObject ( "MSXML2.MXXMLWriter") 
Set oStream = CreateObject ( "ADODB.STREAM") 
oStream.Open 
oStream.Charset = "UTF-8" 

wrt.indent = True 
wrt.encoding = "UTF-8" 
wrt.output = oStream 
Set rdr.contentHandler = WRT 
Set rdr.errorHandler = WRT 
rdr.Parse rXML 
wrt.flush 

oStream.SaveToFile "C:\XML\temp\test_send.xml", 2 

Set rdr = Nothing 
Set WRT = Nothing 
Set xmlDoc = Nothing 

Set xmlhttp = CreateObject("Microsoft.XMLHTTP") 

xmlhttp.open "POST" , "http://testdomain.com:8080/emm_webservice", False 

xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded; charset=UTF-8" 

xmlhttp.setRequestHeader "Content-length", "1000" 

xmlhttp.setRequestHeader "Connection", "close" 

xmlhttp.setRequestHeader "soapAction", "sendMailing" 

Set mXML = CreateObject("Microsoft.XMLDOM") 

mXML.async = False 

mXML.load("C:\XML\temp\test_send.xml") 

xmlhttp.send(mXML) 

If(xmlhttp.readyState = 4) then 

Dim cDOM : Set cDOM = CreateObject("MSXML2.DOMDocument.3.0")
cDOM.loadXML xmlhttp.responseText
cMailingID = cDOM.selectSingleNode("//ns1:sendMailingResponse/sendMailingReturn").Text

Msgbox cMailingID

End If 
At the the next step is to add an error loop so that it sends an email to admin if a mailing fails - rather than displaying a message box with the return value.

Can anyone suggest any improvements - or code to send an alert if the action fails?

No doubt the script could be trimmed back considerably - but, hey, it's working so far ...!

??
Post Reply