1

I've built an XML SOAP API request which retrieves the names of all Automations within our BU. It looks like this:

  SET @endpoint = "https://[endpoint key -censored].soap.marketingcloudapis.com/Service.asmx"
  SET @payload = ""
  SET @payload = Concat(@payload, "<?xml version='1.0' encoding='utf-8'?>")
  SET @payload = Concat(@payload, "<soapenv:Envelope
    xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>")
  SET @payload = Concat(@payload, "<soapenv:Header>")
  SET @payload = Concat(@payload, "<wsse:Security soapenv:mustUnderstand='1'
            xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>")
  SET @payload = Concat(@payload, "<wsse:UsernameToken wsu:Id='UsernameToken-'
                xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>")
  SET @payload = Concat(@payload, "<wsse:Username>[Username -censored]</wsse:Username>")
  SET @payload = Concat(@payload, "<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>[Password -censored]</wsse:Password>")
  SET @payload = Concat(@payload, "</wsse:UsernameToken>")
  SET @payload = Concat(@payload, "</wsse:Security>")
  SET @payload = Concat(@payload, "</soapenv:Header>")
  SET @payload = Concat(@payload, "<soapenv:Body>")
  SET @payload = Concat(@payload, "<RetrieveRequestMsg xmlns='http://exacttarget.com/wsdl/partnerAPI'>")
  SET @payload = Concat(@payload, "<RetrieveRequest>")
  SET @payload = Concat(@payload, "<ObjectType>Program</ObjectType>")
  SET @payload = Concat(@payload, "<Properties>Name</Properties>")
  SET @payload = Concat(@payload, "</RetrieveRequest>")
  SET @payload = Concat(@payload, "</RetrieveRequestMsg>")
  SET @payload = Concat(@payload, "</soapenv:Body>")
  SET @payload = Concat(@payload, "</soapenv:Envelope>")

  HTTPPost2(@endpoint,'text/xml;charset=UTF-8',@payload, false, @output, @respheader,'SOAPAction','Retrieve')

In Postman my response is properly formatted in XML, when I output the response of the HttpPost2() on the CloudPage page I get this:

RetrieveResponseurn:uuid:fdcba7f0-3a6f-4cae-beb5-d6a647df281eurn:uuid:1f75698d-16ca-4312-818a-0067d34feb81http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous2020-02-04T15:15:40Z2020-02-04T15:20:40ZOKfb8113da-d228-47a1-be4f-b595cd30cedc
ACMJourney (copy) - 2019-05-22T050539.309
Brand ATest - 2017-05-17T095401.256
WelcomeJourney test - 2020-01-21T082909.000
ExactEvergageCA - 2020-01-21T043800.430
NoConditions - 2019-12-02T034244.241
Exact WhatsApp Demo - 2020-01-07T060749.923
Import sftpWebActivity Journey Test
Demo audience - 2017-05-18T062455.383
Test Journey Pascal - 2019-12-09T040317.706

I've formatted the response here for readability, as the real response has no line breaks and looks like one giant string and is pretty unreadable. It has no delimiter, so BuildRowSetFromString() doesn't work, BuildRowSetFromXML() doesn't work either. Anyone have a clue how I can process this data into a RowSet or how I can get an response in a XML or delimited format? Or did I forget something in the API call?

0

1 Answer 1

3

Rather than utilize the POST and build out the xml envelope, etc., why not utilize WSProxy inside SSJS and then be able to parse the JSON returned?

WSProxy has better efficiency than AMPscript/SSJS API functions - meaning it will be quicker AND it is returned in a format that is native to SSJS and easily parsed.

e.g.

var prox = new Script.Util.WSProxy();

var cols = ["Name"];
var filter = {
  Property: "Status",
  SimpleOperator: "IN",
  Value: [-1,0,1,2,3,4,5,6,7,8]
};

var res = prox.retrieve("Program", cols, filter);

This would then return a JSON with all your Automation names inside it that you can then use the SSJS to parse.

If you need to convert it back into AMPscript, you can utilize the Variable functions in SSJS to pass them back and forth.

I wrote a quick article on my blog about creating an automation dashboard that may help as well.

1
  • Thanks a lot, this worked like a charm!
    – Rutger
    Commented Feb 5, 2020 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .