FedEx Freight Shipping Rates with Different origin and billing address Rest API.

By | October 26, 2024
Spread the love

To implement FedEx Freight Shipping Rates with different origin and billing addresses using the FedEx REST API, you need to interact with the FedEx Rate API which supports freight shipments, including Freight LTL (Less than Truckload) services. This allows you to retrieve shipping rates while specifying separate origin (shipper) and billing addresses.

Steps for Implementing the FedEx Freight Shipping Rates API:

1. Register and Get FedEx API Credentials

Before using the API, you must sign up for a FedEx Developer Account and generate API credentials for accessing the FedEx APIs. After registration, you will obtain:

  • API Key
  • API Secret
  • Account Number
  • Freight Account Number

These credentials will authenticate your requests.

2. Base URL and Endpoint for FedEx Freight API (REST)

FedEx provides different APIs for their various services. To get freight shipping rates, you will use the FedEx Rates API endpoint:

POST https://apis-sandbox.fedex.com/rate/v1/rates/quotes

(You’ll switch to the production endpoint after testing.)

3. Constructing the API Request

You’ll send a JSON payload to this endpoint with the required information, including shipper address (origin), recipient address (destination), and billing details.

Here’s a breakdown of the key fields for your request:

  • accountNumber: Your FedEx account number.
  • requestedShipment: This object includes details about the shipment:
    • shipper: The origin address (where the freight is shipping from).
    • recipient: The destination address (where the freight is being shipped to).
    • rateRequestType: Set to "ACCOUNT" to use your account rates.
    • requestedPackageLineItems: Details of each shipment package (weight, dimensions, freight class).
    • freightShipmentDetail: Information specific to freight shipments.
    • payor: Who is responsible for paying the shipping (can be the shipper, recipient, or third party).

Here’s an example JSON request:

{
  "accountNumber": {
    "value": "YourAccountNumber"
  },
  "requestedShipment": {
    "shipper": {
      "address": {
        "streetLines": ["123 Origin St"],
        "city": "Origin City",
        "stateOrProvinceCode": "CA",
        "postalCode": "90001",
        "countryCode": "US"
      }
    },
    "recipient": {
      "address": {
        "streetLines": ["456 Destination Ave"],
        "city": "Destination City",
        "stateOrProvinceCode": "TX",
        "postalCode": "73301",
        "countryCode": "US"
      }
    },
    "rateRequestType": ["ACCOUNT"],
    "requestedPackageLineItems": [
      {
        "weight": {
          "units": "LB",
          "value": 500
        },
        "dimensions": {
          "length": 40,
          "width": 48,
          "height": 60,
          "units": "IN"
        },
        "freightClass": "CLASS_050"
      }
    ],
    "freightShipmentDetail": {
      "fedExFreightAccountNumber": "YourFreightAccountNumber",
      "role": "SHIPPER",
      "totalHandlingUnits": 1,
      "palletWeight": {
        "units": "LB",
        "value": 500
      },
      "handlingUnitDescription": "PALLET",
      "totalHandlingUnits": 1
    },
    "payor": {
      "responsibleParty": {
        "accountNumber": {
          "value": "BillingAccountNumber"
        },
        "contact": {
          "personName": "John Doe",
          "phoneNumber": "1234567890"
        },
        "address": {
          "streetLines": ["789 Billing St"],
          "city": "Billing City",
          "stateOrProvinceCode": "NY",
          "postalCode": "10001",
          "countryCode": "US"
        }
      }
    },
    "serviceType": "FEDEX_FREIGHT_ECONOMY",
    "packagingType": "YOUR_PACKAGING",
    "pickupType": "REGULAR_PICKUP"
  }
}

Key Fields Explained:

  • Shipper Address: Specifies the origin where the freight will be shipped from.
  • Recipient Address: Specifies the destination where the freight will be delivered.
  • Payor: The party responsible for payment. You can specify an account number different from the shipper’s account. This can include the billing address, allowing for third-party or recipient billing.
  • Freight Shipment Detail: Contains freight-specific data like pallet count, weight, and freight class.

4. Handle API Response

The API will return a response containing rate information, including shipping costs and estimated delivery dates. Example response:

{
  "rateReplyDetails": [
    {
      "serviceType": "FEDEX_FREIGHT_ECONOMY",
      "ratedShipmentDetails": [
        {
          "totalNetCharge": {
            "amount": 350.00,
            "currency": "USD"
          }
        }
      ]
    }
  ]
}
  • totalNetCharge: This will show the calculated shipping cost based on the request parameters.

5. Testing and Moving to Production

FedEx provides a sandbox environment for testing purposes. After thoroughly testing your integration, you can switch to the production endpoint to use live rates.

Summary

To implement FedEx Freight Shipping Rates with different origin and billing addresses via the REST API:

  • Register for FedEx API credentials.
  • Use the /rate/v1/rates/quotes endpoint.
  • Send a POST request with the shipment details, including separate origin and billing addresses.
  • Handle the response to display or use the freight rates.

Would you like further help with API testing or implementation in a specific environment?

You can use readymade magento 2 plugin https://www.ecomplugins.com/magento2-fedexfreight-shipping-carrier-with-rest-api