Skip to content

Instantly share code, notes, and snippets.

@wrimik
Last active January 25, 2022 18:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wrimik/56cc284b8c9baeb80bd8af70866a4317 to your computer and use it in GitHub Desktop.
Save wrimik/56cc284b8c9baeb80bd8af70866a4317 to your computer and use it in GitHub Desktop.
FedEx Rates NodeJS SOAP Request
var soap = require('soap'); // npm i soap
var url = 'fedex-api/RateService/RateService_v24.wsdl'; // you'll need to download the wsdl file from https://www.fedex.com/en-us/developer/web-services/process.html#StandardServices
// if you change the order of these variables, everything gets fucked up because "wsdl" is a format for developers who have
// landed themselves in a middle circle of hell.
// this points at fedex's production server btw. if you use dev credentials you'll need to change the url WAAAY down
// by the bottom of the file, in "client.setEndpoint('https://ws.fedex.com:443/web-services');"
var data = {
"WebAuthenticationDetail": {
"UserCredential": {
"Key": "======YOUR KEY=======", // you can get the key/password/etc from fedex.com 's developer center
"Password": "=======API PASSWORD====="
}
},
"ClientDetail": {
"AccountNumber": "======ACCOUNT NUMBER======",
"MeterNumber": "======METER NUMBER======"
},
"TransactionDetail": {"CustomerTransactionId": " *** Rate Available Services Request using PHP ***"},
"Version": {"ServiceId": "crs", "Major": "24", "Intermediate": "0", "Minor": "0"},
"ReturnTransitAndCommit": true,
"RequestedShipment": {
"ShipTimestamp": "2019-10-10T17:00:00",
"DropoffType": "REGULAR_PICKUP",
"Shipper": {
"Address": {
"StreetLines": ["100 Main St"],
"City": "CREOLA",
"StateOrProvinceCode": "AL",
"PostalCode": "36525",
"CountryCode": "US"
}
},
"Recipient": {
"Address": {
"StreetLines": ["100 Main St"],
"City": "PINOLE",
"StateOrProvinceCode": "CA",
"PostalCode": "94564",
"CountryCode": "US",
"Residential": true
}
},
"ShippingChargesPayment": {
"PaymentType": "SENDER",
"Payor": {
"ResponsibleParty": {
"AccountNumber": "376080811",
// "Contact": null,
"Address": {"CountryCode": "US"}
}
}
},
"PackageCount": "1",
"RequestedPackageLineItems": [{
"SequenceNumber": 1,
"GroupPackageCount": 1,
// if you change the order this shit breaks because wsdl is a format for dumbasses
"Weight": {
"Units": "LB",
"Value": 5
},
"Dimensions": {
"Length": 10, "Width": 10, "Height": 3, "Units": "IN"
}
}]
}
};
soap.createClient(url, function (err, client) {
if (err) throw err;
client.setEndpoint('https://ws.fedex.com:443/web-services');
client.getRates(data, function (err, result) {
console.log(result)
if (err) throw err;
});
});
@wrimik
Copy link
Author

wrimik commented Oct 8, 2019

I'm either really smart, or really stupid - because getting the fedex api to work using nodeJS / SOAP was a NIGHTMARE - but I did it.

I've searched high and low, and there's literally no example on the whole internet (I read the whole internet) of a FedEx Rates API Request, using NodeJS / SOAP, that works.

Here it is. You may need to npm i soap before running. God help you if this doesn't work, because fedex doesn't actually want people using their APIs

@zbishop3455
Copy link

zbishop3455 commented Apr 29, 2020

Have been pulling my hair out for the past two days! God bless you for posting this gist! I am trying to implement the Process Shipment Request which is very similar... I would only wish working with this WSDL library to my worst enemy. I will follow up if I can get it working!

@umichdoe
Copy link

umichdoe commented Dec 4, 2020

Make sure to change "Major": "24", to the corresponding wsdl file. var url = 'fedex-api/RateService/RateService_v24.wsdl'

For example, I downloaded RateService_v28.wsdl so I changed mine to "Major": "28",

Thanks @wrimik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment