FedEx API Rate Quote Returns 404: “The resource you requested is no longer available”

I’m trying to integrate the FedEx API to get shipping rate quotes in my Node.js application. I’ve followed the documentation, but I’m consistently getting a 404 error with the message:

“The resource you requested is no longer available.”

FedEx API request failed with status: 404
- Response body: {"transactionId": "c2dda9ea-61fa-411a-9e39-e70239ee9370","errors":[{"code":"NOT.FOUND.ERROR","message":"The resource you requested is no longer available. Please modify your request and try again."}]}

I have verified the endpoint URL and the request payload based on the FedEx API documentation. Here is the relevant part of my index.js:

const express = require('express');
const bodyParser = require('body-parser');
const fetch = require('node-fetch');
const path = require('path');

const app = express();
app.use(bodyParser.json());

const FEDEX_OAUTH_URL = 'https://apis.fedex.com/oauth/token';
const FEDEX_API_URL = 'https://apis.fedex.com/rate/v1/rates/quote';
const FEDEX_API_KEY = 'your_api_key';
const FEDEX_SECRET = 'your_api_secret';
const FEDEX_ACCOUNT_NUMBER = 'your_account_number';

async function getFedexToken() {
  const response = await fetch(FEDEX_OAUTH_URL, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: new URLSearchParams({
      grant_type: 'client_credentials',
      client_id: FEDEX_API_KEY,
      client_secret: FEDEX_SECRET
    })
  });

  const responseBody = await response.text();
  if (!response.ok) {
    throw new Error(`Failed to get FedEx OAuth token: ${response.statusText}. Response Body: ${responseBody}`);
  }

  const data = JSON.parse(responseBody);
  return data.access_token;
}

app.post('/compare', async (req, res) => {
  const { originPostcode, originCountry, destinationPostcode, destinationCountry, weight } = req.body;

  const fedexRequest = {
    accountNumber: {
      value: FEDEX_ACCOUNT_NUMBER
    },
    requestedShipment: {
      shipper: {
        address: {
          postalCode: originPostcode,
          countryCode: originCountry.toUpperCase()
        }
      },
      recipient: {
        address: {
          postalCode: destinationPostcode,
          countryCode: destinationCountry.toUpperCase()
        }
      },
      shipDateStamp: new Date().toISOString().split('T')[0], // Today's date in YYYY-MM-DD format
      pickupType: 'DROPOFF_AT_FEDEX_LOCATION',
      serviceType: 'INTERNATIONAL_PRIORITY',
      rateRequestType: ['LIST', 'ACCOUNT'],
      customsClearanceDetail: {
        dutiesPayment: {
          paymentType: 'SENDER',
          payor: {
            responsibleParty: null
          }
        },
        commodities: [
          {
            description: 'Camera',
            quantity: 1,
            quantityUnits: 'PCS',
            weight: {
              units: 'KG',
              value: weight
            },
            customsValue: {
              amount: 100,
              currency: 'USD'
            }
          }
        ]
      },
      requestedPackageLineItems: [
        {
          weight: {
            units: 'KG',
            value: weight
          }
        }
      ]
    }
  };

  console.log('FedEx Request Payload:', JSON.stringify(fedexRequest, null, 2));

  try {
    const token = await getFedexToken();
    const response = await fetch(FEDEX_API_URL, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-locale': 'en_US',
        'Authorization': `Bearer ${token}`
      },
      body: JSON.stringify(fedexRequest)
    });

    const responseBody = await response.text();
    if (!response.ok) {
      console.error('FedEx API request failed with status:', response.status);
      console.error('Response body:', responseBody); // Log the detailed error response
      throw new Error(`FedEx API request failed with status ${response.status}: ${responseBody}`);
    }

    const fedexData = JSON.parse(responseBody);
    console.log('FedEx Response Data:', JSON.stringify(fedexData, null, 2));

    if (!fedexData.output || !fedexData.output.rateReplyDetails) {
      throw new Error(`Unexpected FedEx API response structure: ${JSON.stringify(fedexData)}`);
    }

    const results = fedexData.output.rateReplyDetails.map(detail => ({
      courier: 'FedEx',
      cost: detail.ratedShipmentDetails[0].totalNetChargeWithDutiesAndTaxes.amount,
      service: detail.serviceType,
      transitTime: detail.commitDetails[0].commitTimestamp
    }));

    res.json({ results });
  } catch (error) {
    console.error('Error fetching data from FedEx API:', error);
    res.status(500).json({ error: error.message });
  }
});

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

const PORT = process.env.PORT || 3001;

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
}).on('error', (err) => {
  if (err.code === 'EADDRINUSE') {
    console.error(`Port ${PORT} is already in use.`);
  } else {
    console.error(err);
  }
});

I was expecting to receive a rate quote from FedEx for the shipment details provided, but instead, I keep receiving a 404 error. I have validated the endpoint and the request payload structure, but I am unsure what is causing the resource to be “no longer available.”

Questions:

  • Is the endpoint URL correct for obtaining rate quotes?
  • Does the payload structure meet the FedEx API requirements?
  • Are there any additional headers or parameters required that I might be missing?

New contributor

Bigshow77 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật