2

I am trying to make a SOAP call following from the answer here :

Server-Side Javascript calling SOAP API

I am running this on a cloud page.

When I publish it, it doesnt render (harbinger or bad times) and when I try to visit the cloud page, I get a 500 error. It is not logging the error in the results string.

<script language='javascript' runat=server>
    Platform.Load("core","1");
    var username = 'xxxxxx';
var password = 'xxxxx!';
var payload = '';
var endpoint = "https://webservice.s7.exacttarget.com/Service.asmx";
var result;

payload += '<?xml version="1.0" encoding="utf-8"?>';
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">';
payload += '   <soapenv:Header>';
payload += '      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">';
payload += '         <wsse:UsernameToken wsu:Id="UsernameToken-32259181" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
payload += '            <wsse:Username>' + username + '</wsse:Username>';
payload += '            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + password + '</wsse:Password>';
payload += '         </wsse:UsernameToken>';
payload += '      </wsse:Security>';
payload += '   </soapenv:Header>';
payload += '   <soapenv:Body>';
payload += '        <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">';
payload += '            <RetrieveRequest>';                     
payload += '                <ObjectType>AccountUser</ObjectType>';
payload += '                <QueryAllAccounts>true</QueryAllAccounts>';
payload += '                <Properties>email</Properties>';
payload += '                <Properties>ActiveFlag</Properties>';
payload += '                <Properties>CreatedDate</Properties>';
payload += '                <Properties>UserID</Properties>';
payload += '                <Properties>LastSuccessfulLogin</Properties>';
payload += '            </RetrieveRequest>';
payload += '        </RetrieveRequestMsg>';
payload += '   </soapenv:Body>';
payload += '</soapenv:Envelope>';

try {
    result = HTTP.Post(endpoint,"text/xml",payload,["SOAPAction"],["Retrieve"]);
    result = {StatusCode:500,Response:Stringify(e)};
}

if (result.StatusCode != 200) {
    //Bad response
    Write(Stringify(result));
} else {
    //Good response
    Write(Stringify(result));
}
    </script> 

I would appreciate it if anyone can point me in the right direction.

1 Answer 1

3

Looks like you are missing the 'catch' part of your try/catch. I believe this may be causing your error.

try {
    result = HTTP.Post(endpoint,"text/xml",payload,["SOAPAction"],["Retrieve"]);
} catch(e) {
    result = {StatusCode:500,Response:Stringify(e)};    
}
2
  • Greetings! I am trying the code above in CloudPages and I am getting this result: {"StatusCode":200,"Response":[""]}. I am doing the same call via SOAPUI and I am getting the correct response. I am using this to output the responses: Write(Stringify(result));. I was wondering what I am doing wrong? Thanks
    – user5105
    Commented Apr 16, 2020 at 19:00
  • 1
    I figured it out. I turns out that I need to publish the page. I didn't want to publish for security reasons but after I published now I see the results. Thanks!
    – user5105
    Commented Apr 16, 2020 at 20:06

You must log in to answer this question.

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