2

I got OK when I was testing Marketing Cloud SOAP API with SoapUI tool.

So then I tried to send http request in apex, but I got 500 result: Status=Internal Server Error, StatusCode=500

The code is following:

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://webservice.s7.exacttarget.com/Service.asmx');
req.setMethod('POST');

String eBody = '';
eBody += '<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">';
eBody += '<soapenv:Header>';
eBody += '<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">';
eBody += '<wsse:UsernameToken wsu:Id="UsernameToken-32259181" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
eBody += '<wsse:Username>xxxx</wsse:Username>';
eBody += '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxx</wsse:Password>';
eBody += '</wsse:UsernameToken>';
eBody += '</wsse:Security>';
eBody += '</soapenv:Header>';
eBody += '<soapenv:Body>';
eBody += '<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">';
eBody += '<RetrieveRequest>';
eBody += '<ObjectType>Email</ObjectType>';
eBody += '<Properties>Name</Properties>';
eBody += '<Properties>Subject</Properties>';
eBody += '<Properties>HTMLBody</Properties>';
eBody += '</RetrieveRequest>';
eBody += '</RetrieveRequestMsg>';
eBody += '</soapenv:Body>';
eBody += '</soapenv:Envelope>';

req.setBody(eBody);
HttpResponse res = http.send(req);

// Log the XML content
System.debug('qqqq res.getBody=' + res.getBody());
2
  • 1
    Probably you are missing headers which should be part of the request to exact target
    – Ashwani
    Oct 16, 2015 at 11:10
  • I think so, but I dont know which header infomations should be added because this is the first time I use soap api.
    – Leisure
    Oct 19, 2015 at 2:56

1 Answer 1

1

I`m pleased to share the answer when I successfully resolved the issue.

We need to clarify the soap action and put it in to the header information when we are going to access ExactTarget SOAP API, like as:

req.setHeader('SOAPAction', 'Retrieve');

AND IF the content type is xml, then we will add additional header information:

req.setHeader('Content-Type', 'text/xml;charset=UTF-8');

And then, I got the correct content from the response message.

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.