2

I would like to connect to Microsoft Dynamics GP from Salesforce using NTLM Authentication. I used this library to Authenticate the service (https://github.com/natewallace/ApexNTLM), I prepare a hardcoded body XML message but always I get a Bad request response, even it seems is connected. Here's my code

@future(callout=true)
global static void sendCallout(){

    String username      = 'MYDOMAIN\\USERNAME';
    String password      = 'MYPASSWORD';  

    HttpClient httpObj   = new HttpClient(username,password,True);      
    HttpRequest req      = new HttpRequest(); 

    Map<String,String> headerMap = new Map<String,String>();
    headerMap.put('SOAPAction','GetItemList');
    headerMap.put('Content-Type','text/xml;charset=UTF-8');
    headerMap.put('Accept-Encoding','gzip,deflate');

    String requestString = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.microsoft.com/dynamics/gp/2006/01" xmlns:ns1="http://schemas.microsoft.com/dynamics/2006/01" xmlns:ns2="http://schemas.microsoft.com/dynamics/security/2006/01"><soapenv:Header/><soapenv:Body><ns:GetCustomerList><!--Optional:--><ns:criteria></ns:criteria><!--Optional:--> <ns:context><!--Optional:--><ns1:CompanyKey>34</ns1:CompanyKey></ns:context></ns:GetCustomerList></soapenv:Body></soapenv:Envelope>';

    System.debug('##BODY: '+requestString);
    req.setEndpoint('http://myservice/DynamicsGPWebServices/DynamicsGPService.asmx');
    req.setMethod('POST');
    req.setBody(requestString);
    Httpresponse res = new Httpresponse();
    res = httpObj.send(req,headerMap);

    System.debug('### Response: '+res);
}

Any ideas to achieve the conection, basically I would like to get the item list provided from the service.

4
  • Dynamics is tough, read answers here: salesforce.stackexchange.com/questions/5224/… - Dynamics requires windows domain authentication – Eric Mar 2 '17 at 14:29
  • Does the same request work from something like SOAP UI? Look for the raw CALLOUT_REQUEST in the Apex Debug log. – Daniel Ballinger Mar 3 '17 at 0:35
  • Not working in SOAPUI neither, I know if working because I created an application in Mulesoft and works fine, I assume maybe it's the body structure or something – Yucel Mar 3 '17 at 1:32
  • @Edgar I am also strucked same GP to salesforce apex integration, you got any solution for this integration – Sfdcprgmr Feb 28 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.