20

I am using nodejs soap module to call fedex services but getting an error:

  {
   "HighestSeverity": "ERROR",
   "Notifications": [
         {
         "Severity": "ERROR",
         "Source": "prof",
         "Code": "1000",
         "Message": "Authentication Failed"
         }
    ],
 "Version": {
    "ServiceId": {},
     "Major": {},
    "Intermediate": {},
   "Minor": {}
  }
}    

Below is my nodejs code:

var data = {};

data["WebAuthenticationDetail"] = {
    "UserCredential": {
        "Key": developer_key,//getProperty('key');
        "Password": password
    }
};

//console.log(JSON.stringify(data));

data['ClientDetail'] = {
    'AccountNumber': account_number,//getProperty('shipaccount');
    'MeterNumber': meter_number//getProperty('meter');
};

data['Version'] = {
    'ServiceId': 'crs',
    'Major': 14,
    'Intermediate': 0,
    'Minor': 0

};

var soap = require('soap');
var path = require('path');
var path_to_wsdl = path.resolve(__dirname + '/wsdl/RateService_v14.wsdl');

soap.createClient(path_to_wsdl, function (err, client) {
    if (err)throw err;
    client.getRates(data, function (err, result) {
        if (err)throw err;
        res.send(result);
    });
});

But when i am sending this data with php below one then it's working.

$path_to_wsdl = "wsdl-testing/RateService_v14.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl /*, array('trace' => 1) */);

$request['WebAuthenticationDetail'] = array(
      'UserCredential' => array(
                   'Key' => $developer_key, 
                   'Password' => $password
  ) );

 $request['ClientDetail'] = array(
                       'AccountNumber' => $account_number, 
                       'MeterNumber' => $meter_number,
                   );

$request['Version'] = array(
                          'ServiceId' => 'crs', 
                           'Major' => '14', 
                          'Intermediate' => '0', 
                          'Minor' => '0');
$response = $client -> getRates($request);

Logger::info('here is the response====', $response);

Same code is working in php but not in Nodejs. Please let me know where is the issue?

Rohit
  • 2,987
  • 3
  • 25
  • 50
  • have you got the answer? I am having the same problem with magento... getting same response.. – Nishant Solanki Apr 25 '14 at 07:10
  • This is the problem with Fedex. Fedex is not parsing data on its end. Now i am sending data in the same format as included in sample code files. – Rohit Apr 25 '14 at 07:34
  • I would use a tool like fiddler (http://www.telerik.com/fiddler) that can look at the traffic as it goes across the wire. There is probably some header or something that isn't explicitly set in nodejs, but is through php. – Jon Sturdevant Jul 31 '14 at 19:56
  • I'd recommend trying https://requestb.in to test your API calls and see how thy are different from each other. You should be able to spot the problem quite easily this way :) – David Gatti Sep 15 '17 at 08:05

4 Answers4

1

You could try using the node-shipping-fedex module insterad of using soap directly. https://github.com/typefoo/node-shipping-fedex

Lucas
  • 1,221
  • 9
  • 10
1

I note you pasted this:

  {
   "HighestSeverity": "ERROR",
   "Notifications": [
         {
         "Severity": "ERROR",
         "Source": "prof",
         "Code": "1000",
         "Message": "Authentication Failed"
         }
    ],
 "Version": {
    "ServiceId": {},
     "Major": {},
    "Intermediate": {},
   "Minor": {}
  }
}

Is this the response that you received from the SOAP web service?

If so then you have successfully connected to and received a response, albeit containing an error specifying the following: Authentication Failed.

In the createClient() function, is there a possibility to set namespaces and prefixes that are specific to the Fedex web service in question?

Do you have a copy of the WSDL? If you do you could find out more details about exactly how the web service needs to be called and exactly what format the operations need to be called in.

I am not sure of the internal workings of the Node.js SOAP Client but what I do know is that in PHP sometimes when creating a SimpleXMLElement instance it is necessary to register the namespaces against the object in order to traverse the SOAP response with XSLT in PHP.

0

My guess is that you're using the test URLs in PHP but the live URLs in node.js. In your PHP code you use wsdl-test/ and in your node.js code you use wsdl/. If you're indeed using the test WSDL files in PHP, then I think you're ultimately resolving to https://wsbeta.fedex.com:443/web-services/rate while in node.js you're resolving to https://ws.fedex.com:443/web-services/rate where you probably don't have live access yet.

Charlie Schliesser
  • 7,851
  • 4
  • 46
  • 76
0

You need to set the endpoint of the client to FedEx web services (live or sandbox) url

soap.createClient(url, function (err, client) {
    if (err)throw err; 
    //set the url before firing the function
    client.setEndpoint('https://ws.fedex.com:443/web-services');
    client.getRates(data,  function (err, result) {
        console.log(result)
        if (err)throw err;
    });
});
Mike Wright
  • 111
  • 1
  • 2