0

I'm trying to use HTTPPOST2 function to make an SOAP API call.

Here is what my code looks like

%%[
    var @output,@respheader,@payload,@endpoint,@callstatus,@callresponse
    set @endpoint = 'https://test.com'  
    set @payload = '
    <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:urn="urn:enterprise.soap.sforce.com">
      <soapenv:Header>
      </soapenv:Header>
      <soapenv:Body>
      <urn:login>
      <urn:username>"xxx@test.com"
      </urn:username>
      <urn:password>"xxx"
      </urn:password>
      </urn:login>
      </soapenv:Body>
      </soapenv:Envelope>'
 ]%%
%%=HTTPPost2(@endpoint,'text/xml', @payload, true,@callstatus,@callresponse)=%%

I'm not sure why it errored out. Could someone give me any insights on this?

Many thanks

  • I'm assuming you've replaced the actual URL you're posting to? What happens if you replace the Raise Error parameter with false? – Macca May 4 '17 at 7:04
  • Hi Andrew, thanks so much for the quick response. I did change the parameter to false. Now it returns loginInvalid error. I'm sure the username and password are correct since I've made test call using SOAP UI. I was wondering if there anything to do with the username includes @ symbol and AMPscript recognise it as a variable? I couldn't think of any other reason why this is not working, – Ash Wu May 4 '17 at 7:39
  • The '@' Symbol would not be causing an issue for AMPScript, no. It must be something else. Maybe content type or headers. Check exactly what you're posting in SOAP UI matches what you're doing here with AMPScript. – Macca May 4 '17 at 7:50
  • Ok, thanks so much for your help. Just an additional question for this case. When I successfully make the call, would I be able to get the callresponse as XML and using BuildRowSetFromXML function to process it further? – Ash Wu May 4 '17 at 8:08
  • Yes. Most likely. – Macca May 4 '17 at 8:30
1

When debugging the HttpPost2 AMPScript function, it is useful to change the behaviour of the function to not raise a system error when an error is returned by the HTTP request itself (fourth parameter of the function). You can inspect the HTTP error itself.

0

I was successfully able to post the SOAP call using AMPscript. In your case it failed because that's not a valid endpoint.

If you are trying to post SOAP to the SFMC SOAP API, then add in a SOAPAction parameter.

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

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.