Saturday 22 April 2017

FedEx Rate Request with node.js using node-soap

I'm trying to make a simple rate request to the FedEx API using node-soap. I've read through the documentation and the WSDL to include all the required information but all I get is an empty object as response.

Since I'm not getting any errors I'm not sure what I'm doing wrong or if I'm missing some step.

Here's my code:

var express = require('express');
var app = express();
var port = process.env.PORT || 7000;
var path = require('path');
var soap = require('soap');

var url = path.join(__dirname, 'wsdl', 'RateService_v20.wsdl');

var params = {
      WebAuthenticationDetail: {
        UserCredential: {
          Key: 'the key I was given by FedEx',
          Password: 'the password I was given'
        }
      },
      ClientDetail: {
        AccountNumber: 'the acc number I was given',
        MeterNumber: 'the meter number I was given',
        Localization: {
            LanguageCode: 'EN'
        }
      },
      Version: {
        ServiceId: 'crs',
        Major: '20', 
        Intermediate: '0',
        Minor: '0'
      },
      RateRequest: {  
        ReturnTransitAndCommit: true,
        RequestedShipment: {
            DropoffType: 'REGULAR_PICKUP',
            PackagingType: 'FEDEX_10KG_BOX',
            RateRequestTypes: 'LIST',
            PackageCount: '1',
            Shipper: {
                Contact: {
                    PersonName: 'Sender Name',
                    CompanyName: 'Company Name',
                    PhoneNumber: '5555555555'
                },
                Address: {
                    StreetLines: [
                    'Address Line 1'
                    ],
                    City: 'Collierville',
                    StateOrProvinceCode: 'TN',
                    PostalCode: '38017',
                    CountryCode: 'US'
                }
            },
            Recipient: {
                Contact: {
                    PersonName: 'Recipient Name',
                    CompanyName: 'Company Receipt Name',
                    PhoneNumber: '5555555555'
                },
                Address: {
                    StreetLines: [
                    'Address Line 1'
                    ],
                    City: 'Charlotte',
                    StateOrProvinceCode: 'NC',
                    PostalCode: '28202',
                    CountryCode: 'US'
                }
            }
        }
    }
};

app.get('/describe',function(req,res){
    soap.createClient(url, function(err, client) {
        if (err) throw err; 
        res.send(client.describe());
    });
});

app.get('/test',function(req,res){
    soap.createClient(url, function(err, client) {
        if (err) throw err; 
        client.RateService.RateServicePort.getRates(params, function(err, result) {
          res.send(result);
      });
    });
})

app.listen(port, function(){
    console.log('app listening on port '+ port);
})



via Matheus Alves

No comments:

Post a Comment