0

I have a number of clients who use our integration with Salesforce Marketing Cloud. When things go astray it is quite difficult to resolve the issue as I have no access to the clients account.

We use a SOAP call, where we define the endpoint, and authenticate with a traditional username and password

      CustomBinding exactTargetBinding = new CustomBinding();
      exactTargetBinding.Name = "ExactTargetAPI";
      exactTargetBinding.CloseTimeout = new TimeSpan(0, 0, 30, 0);
      exactTargetBinding.OpenTimeout = new TimeSpan(0, 0, 30, 0);
      exactTargetBinding.ReceiveTimeout = new TimeSpan(0, 0, 30, 0);
      exactTargetBinding.SendTimeout = new TimeSpan(0, 0, 30, 0);

      TransportSecurityBindingElement securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
      TextMessageEncodingBindingElement textMessageEncodingBindingElement = new TextMessageEncodingBindingElement();
      textMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap11WSAddressingAugust2004;
      HttpsTransportBindingElement httpsTransportBindingElement = new HttpsTransportBindingElement();
      httpsTransportBindingElement.MaxReceivedMessageSize = 655360000;

      exactTargetBinding.Elements.Add(securityBindingElement);
      exactTargetBinding.Elements.Add(textMessageEncodingBindingElement);
      exactTargetBinding.Elements.Add(httpsTransportBindingElement);

      exactTargetClient = new SoapClient(exactTargetBinding, new EndpointAddress(exactTargetWSServiceURL));
      exactTargetClient.ClientCredentials.UserName.UserName = username;
      exactTargetClient.ClientCredentials.UserName.Password = password;

When we make a SOAP call based on our clients endpoint, username and password, we get back an exception

An invalid security token was provided

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Apteco.EmailResponse.ExactTarget.ExactTargetAPI.Soap.Extract(ExtractRequest1 request)
at 

My simple question is can a clients system be setup in such a way as to forbid the use of authentication by username and password?

And is there an email address where I can get a salesforce representative to fix the settings if things can be setup in this manner?

I know this is all a bit vague... 20 years ago I would just have sent an email to [email protected]

:-)

Thanks Simon

3
  • 1
    Username/password/API User auth has been or soon will be deprecated. Might as well transition to OAuth. Wouldn't be surprised if SF hasn't started reaching out to those accounts still using it. It's been on the way out for years now. There's no email address for support. Clients to can originate cases from the upper right corner: (user drop down) -> Salesforce Help & Training Commented Jun 20, 2022 at 20:13
  • Hi Adam, thanks for the reply. We do already use some of the RESTful calls, and so we already generate the tokens. I have had a look at trying to get the SOAP calls to use the token rather than the email and password, but the documentation is quite sparse. The closest docs are developer.salesforce.com/docs/marketing/marketing-cloud/guide/…, but it is using the standard username and password. Would be grateful if there was a pointer to some docs on how to setup your SOAP calls to use the username with a token rather than password.
    – Simon
    Commented Jun 21, 2022 at 11:39
  • Added an answer down below. Commented Jun 21, 2022 at 12:08

2 Answers 2

0

Using a token in a SOAP call can be done like this:

POST /Service.asmx HTTP/1.1
Host: YOURTENANTHERE.soap.marketingcloudapis.com

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://exacttarget.com/wsdl/partnerAPI">
    <soapenv:Header>
        <fueloauth xmlns="http://exacttarget.com">YOURTOKENHERE</fueloauth>
    </soapenv:Header>
    <soapenv:Body>
        <par:SystemStatusRequestMsg/>
    </soapenv:Body>
</soapenv:Envelope>
1
  • Adam, thanks for this. I now have it all working. In the end I wrote a bit of a wrapper to add the headers if I was using oAuth
    – Simon
    Commented Jun 21, 2022 at 16:36
0
    private T CallSoapRequest<T>(Func<T> func)
    {
      if (useOAuth)
      {
        using (new OperationContextScope(exactTargetClient.InnerChannel))
        {
          // Add oAuth token to SOAP header.
          var xmlHeader = MessageHeader.CreateHeader("fueloauth", "http://exacttarget.com", restClient.GetAccessToken().Result.AccessToken);
          OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader);

          var httpRequest = new System.ServiceModel.Channels.HttpRequestMessageProperty();
          OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);
          httpRequest.Headers.Add(HttpRequestHeader.UserAgent, "FuelSDK-C#-v1.3.0");

          return func();
        }
      }
      else
      {
        return func();
      }
    }

You must log in to answer this question.

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