0

I am trying to find a way to automate a SOAP call and have the response which is in XML format being parsed and put into a data extension in the proper format (data to columns)

I can create the SOAP call in a Cloud Page fine which outputs the response like this

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <soap:Header>
      <wsa:Action>RetrieveResponse</wsa:Action>
      <wsa:MessageID>xxxxx</wsa:MessageID>
      <wsa:RelatesTo>xxxxxx</wsa:RelatesTo>
      <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
      <wsse:Security>
         <wsu:Timestamp wsu:Id="Timestamp-45ba12be-1b6d-4f55-a5c3-af7f0b21dddd">
            <wsu:Created>2019-09-30T16:42:48Z</wsu:Created>
            <wsu:Expires>2019-09-30T16:47:48Z</wsu:Expires>
         </wsu:Timestamp>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <OverallStatus>OK</OverallStatus>
         <RequestID>xxxxxxxxxx</RequestID>
         <Results xsi:type="AccountUser">
            <Client>
               <ID>xxxxx</ID>
            </Client>
            <PartnerKey xsi:nil="true"/>
            <ID>10287676</ID>
            <ObjectID xsi:nil="true"/>
            <UserID>[user]</UserID>
            <Name>[Name]</Name>
            <Email>[Email]</Email>
            <ActiveFlag>true</ActiveFlag>
            <Delete>0</Delete>
         </Results>

What I tried doing is create another cloud page with Ampscript and use the HTTPGet method parsing the response cloud page to parse the elements and the write to a data extension.

The code I am using to parse the SOAP response

%%[VAR @xml, @userid, @email, @activeflag, @rows, @cnt 

SET @xml = HTTPGet("https://pub.s1.exacttarget.com/page")
SET @userid = BuildRowsetFromXML(@xml,"//Results/UserID",1)
SET @email = BuildRowsetFromXML(@xml,"//objectid/email",1)
SET @activeflag = BuildRowsetFromXML(@xml,"//objectid/activeflag",1)

IF RowCount(@userid) > 5 THEN
SET @rows = 5
ELSE
SET @rows = RowCount(@userid)
ENDIF

IF @rows >= 1 THEN
FOR @cnt = 1 to @rows DO
SET @userid = Field(Row(@userid,@cnt),"Value")

]%%





%%=v(@userid)=%%
%%[NEXT @cnt
ENDIF
]%%

Is it because it is not formed as a typical xml but a SOAP envelope? Or is there a better way of doing this?

The code isn't perfect as I am just trying to test that it actually can parse the XML but nothing is coming back.

0

I think you can't use the : characters in element names in order for the BuildRowsetFromXML functions to work. You might also want to remove all namespaces first as well. You can do both of these via ampscript replace methods prior to building your rowset. You want the XML you're trying to parse to be super-simple.

You could also try to use TranformXML to turn the response into a text representation of the code you need to execute and put that string through a TreatAsContent call. Probably a bad idea when you think about it, but it would likely work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.