1

I want to retrieve data from Marketing Cloud Data Extension. Turns out there isn't any REST API for that. Retrieve Data from a Data Extension shows SOAP API can be used but there are no sample for apex. I have used Exact Target Partner WSDL to generate Apex class. Authenticate SOAP API describes the access token approach (fuelouath in header of soap envelope), it works fine with SoapUI. But there is no reference to the same in the generated Apex class.

The question in this link uses fueloauth header.

  • What all changes are needed in the auto generated Apex class so as to authenticate using access token in Apex? Snippet from link.
  • Any other way to authenticate from existing Apex class.

What all changes are needed in the auto generated Apex class so as to authenticate using access token in Apex? Snippet from link above.

ET_WSDL.Soap soapRequest = new ET_WSDL.Soap();
ET_WSDL.fueloauth header = new ET_WSDL.fueloauth();

header.fueloauth = 'MyAuthtoken';
soapRequest.HeaderFOAuth = header;

Your help is really appreciated. Thanks in advance.

1

According to Authenticate Your SOAP API Calls you want to include a fueloauth soap header in the request:

<soap:header>
  <fueloauth>YOUR_ACCESS_TOKEN</fueloauth>
</soap:header>

I've covered this more generically in Salesforce passing value in soap header.

Normally the WSDL would define how this header should be created and then the generated Apex code would include the classes and members to do so. I.e. the SoapBinding operations would include one or more <soap:header elements under the input elements to indicate which headers should be sent with each operation.

You can do so manually if required. However, one big challenge here is that the fueloauth header is a string literal rather than a wrapped document literal.

Try something like the following, but it is unlikely to create the correct header.

public class fueloauth_element {
     public string headerValue;
     private String[] headerValue_type_info = new String[]{'fueloauth','namespace','','1','1','false'};
     private String[] apex_schema_type_info = new String[]{'namespace','true','false'};
     private String[] field_order_type_info = new String[]{'headerValue'};
}

Then, in you port class (which includes the endpoint_x member:

public fueloauth_element fueloauth;
private String fueloauth_hns = 'fueloauth=namespace';

I'm doubtful that will work as it won't generate the required string literal. See Integrating Salesforce CRM to Exact Target.

Instead you could generate the raw Apex HttpRequest from the WSDL and then modify that as required to include the soap header.

  • Thanks for your help Daniel. But this didn't create the correct header. Could you please elaborate on "Instead you could generate the raw Apex HttpRequest from the WSDL and then modify that as required to include the soap header." – Pranav Parakh Jul 29 '19 at 4:52
  • @PranavParakh I release a free tool via my employer called the FuseIT SFDC Explorer. Part of that tool is an alternative version of WSDL2Apex that creates the Apex classes from the WSDL. It has options to generate raw Apex HttpRequest options that will POST the SOAP request and then parse the response. These can be modified to send whatever header you want. See How to create HttpRequest body as plain string from WSDL? – Daniel Ballinger Jul 30 '19 at 1:25

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.