We build custom applications 5x faster and cheaper đ
Book a Free Consultation
Stuck on an error? Book a 30-minute call with an engineer and get a direct fix + next steps. No pressure, no commitment.
To integrate Replit with the FedEx API, you need to register for a FedEx Developer Account, generate your FedEx API credentials (Client ID and Client Secret), store them securely using Replit Secrets, and then use HTTP requests (REST API calls) from your server inside a Repl to communicate with FedExâs endpoints. Youâll typically do this using Node.js or Python inside a Repl, sending JSON payloads to FedExâs REST endpoints for tasks like address validation, tracking, or shipping label generation. The integration works like any API connection â you authenticate, request, and handle responses â but youâll explicitly manage environment variables, server ports, and live debugging through Replitâs runtime.
// Load Express and Axios
import express from "express";
import axios from "axios";
const app = express();
app.use(express.json());
const FEDEX_CLIENT_ID = process.env.FEDEX_CLIENT_ID;
const FEDEX_CLIENT_SECRET = process.env.FEDEX_CLIENT_SECRET;
async function getAccessToken() {
// OAuth2 token request
const tokenRes = await axios.post("https://apis-sandbox.fedex.com/oauth/token", {
grant_type: "client_credentials",
client_id: FEDEX_CLIENT_ID,
client_secret: FEDEX_CLIENT_SECRET
});
return tokenRes.data.access_token;
}
app.get("/track/:trackingNumber", async (req, res) => {
try {
const token = await getAccessToken();
const { trackingNumber } = req.params;
// FedEx Tracking API call
const trackRes = await axios.post(
"https://apis-sandbox.fedex.com/track/v1/trackingnumbers",
{
trackingInfo: [{ trackingNumberInfo: { trackingNumber } }]
},
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
}
}
);
res.json(trackRes.data);
} catch (err) {
console.error("FedEx API error:", err.response?.data || err.message);
res.status(500).send("Error communicating with FedEx API");
}
});
// Bind to 0.0.0.0 for Replit
app.listen(3000, "0.0.0.0", () => console.log("Server running on port 3000"));
Following this structure, your Replit server will authenticate with FedEx via OAuth2, make secure REST calls, and expose simple endpoints that can track shipments, create labels, or retrieve rates. Everything is explicit and debuggable within Replitâs live environment.
1
Integrate the FedEx API in a Replit-backed small eCommerce app to automatically create and print shipping labels when a new order is placed. Inside your full-stack Repl, the backend connects to the FedEx Ship API using REST calls, authenticates with your FedEx credentials stored as Replit Secrets, and returns a label (PDF or PNG) to be displayed or printed from the frontend. The Repl runs continuously when testing via Workflows, and all responses are visible in Replitâs built-in console for debugging. Once stable, this logic can be deployed as a Replit Deployment, handling label creation on demand through HTTPS endpoints.
// Example of a POST call to FedEx Ship API from Replit
import express from "express";
import fetch from "node-fetch";
const app = express();
app.use(express.json());
app.post("/create-label", async (req, res) => {
const response = await fetch("https://apis.fedex.com/ship/v1/shipments", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.FEDEX_ACCESS_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify(req.body)
});
const data = await response.json();
res.json(data);
});
app.listen(3000, "0.0.0.0", () => console.log("Running on 3000"));
2
Use the FedEx Tracking API to provide real-time package updates for your customers inside your Replit-hosted application. The backend communicates with the FedEx /track/v1/trackingnumbers endpoint to retrieve status updates, while the frontend visualizes this data. This Replit app can be integrated with a database like Replit DB or an external persistent store to remember shipment numbers between restarts. The live logs and localhost-style Preview allow you to adjust request headers or handle rate limits effectively.
// FedEx Tracking API request from inside the Repl
const trackPackage = async (trackingNumber) => {
const response = await fetch("https://apis.fedex.com/track/v1/trackingnumbers", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.FEDEX_ACCESS_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ trackingInfo: [{ trackingNumberInfo: { trackingNumber } }] })
});
return await response.json();
};
3
Enable real-time updates inside your Replit app using FedEx Webhooks. When FedEx sends event notifications (for example, "Delivered" or "In Transit"), your Replâs Express.js server receives and processes them instantly. You can validate these webhooks with a verification token stored as a Replit Secret. Since Replit provides a persistent HTTPS endpoint while the Repl or Deployment is running, you can test webhook flows effectively with tools like FedEx Webhook Sandbox. These events can trigger email notifications or database updates to keep customer order pages fresh.
// Webhook endpoint to handle FedEx delivery event notifications
app.post("/fedex/webhook", express.json(), (req, res) => {
const signature = req.headers["x-fedex-signature"];
if (signature !== process.env.FEDEX_WEBHOOK_SECRET) {
return res.status(403).send("Forbidden");
}
console.log("FedEx event:", req.body);
// Process event (update DB, send email, etc.)
res.send("OK");
});
Speak oneâonâone with a senior engineer about your noâcode app, migration goals, and budget. In just half an hour youâll leave with clear, actionable next stepsâno strings attached.
1
In Replit, the correct and secure way to store your FedEx API keys is by using Replit Secrets. You create a secret, which behaves like an environment variable. Your code can then safely read it without exposing the key in your files. In the Replit UI, open the "Secrets" tab (lock icon), add the key (for example "FEDEX_API_KEY"), and enter its value. Then, in your code, access it through process.env.FEDEX_API_KEY if using Node.js. This avoids ever hardcoding credentials in the source.
// Example Node.js request to FedEx API
import fetch from "node-fetch"
const FED_EX_KEY = process.env.FEDEX_API_KEY // read from Replit secret
async function getTrackingInfo() {
const res = await fetch("https://apis.fedex.com/track/v1/trackingnumbers", {
method: "POST",
headers: {
"Authorization": `Bearer ${FED_EX_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ trackingInfo: [{ trackingNumberInfo: { trackingNumber: "123456789012" } }] })
})
const data = await res.json()
console.log(data)
}
getTrackingInfo()
Tip: Never log or echo the secret. Anyone with Replit edit access can view secrets, but it wonât be exposed publicly or in your deployed URL. Secrets persist between runs but arenât versioned with code.
2
When FedEx API returns a CORS error while you test from a Replit web server, the reliable fix is to never call the FedEx API directly from the browser. Instead, create a small backend route inside your Repl (using Express or Flask) that sends the request to FedEx from the server side. Browsers enforce CORS, servers do not, so moving the API call to your backend completely bypasses this restriction. Replit provides a public URL for your backend (bound to 0.0.0.0 with an exposed port), so the browser can safely talk to your backend only.
The FedEx API doesnât include CORS headers allowing arbitrary browser origins, meaning browsers block direct calls for security. When you proxy through your Replit backend server, the browser no longer requests FedEx directly, so no CORS is enforced. You can securely keep your FedEx credentials in Replit Secrets as environment variables too.
// Example Express proxy endpoint on Replit
import express from "express"
import fetch from "node-fetch"
const app = express()
app.get("/fedex", async (req, res) => {
const response = await fetch("https://apis.fedex.com/some-endpoint", {
headers: { "Authorization": `Bearer ${process.env.FEDEX_TOKEN}` }
})
const data = await response.json()
res.json(data) // Send result back to the browser
})
app.listen(process.env.PORT, "0.0.0.0")
In your frontend, call /fedex instead of FedEx directly. This pattern ensures reliable CORS handling within Replitâs runtime model.
3
Most often the FedEx JSON not showing in Replit console means you didnât correctly await or parse the response. In Node.js (Replit default runtime), you must use await fetch() and then call response.json() inside an async function. Also ensure your API credentials are safely stored in Replit Secrets and the endpoint you call returns proper application/json.
// Example: Fetch FedEx API rates endpoint
import fetch from "node-fetch"
const FED_EX_KEY = process.env.FEDEX_KEY // stored in Replit Secrets
async function getFedExRates() {
const res = await fetch("https://apis.fedex.com/rate/v1/rates/quotes", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${FED_EX_KEY}`
},
body: JSON.stringify({ /* your request payload */ })
})
const data = await res.json() // parse JSON body
console.log(data) // shows full JSON in Replit console
}
getFedExRates()
This pattern ensures Replit shows a readable JSON object in the console. Always check response.ok before parsing if you suspect API errors.
A common mistake is storing the FedEx OAuth access token directly in Replit code or a JSON file. This token expires quickly, and hardcoding it breaks after expiration. Always use Replit Secrets for your FedEx CLIENT_ID and CLIENT_SECRET, then request a fresh access token dynamically before API calls.
// Requesting a FedEx OAuth token using credentials from Replit Secrets
const tokenResp = await fetch("https://apis.fedex.com/oauth/token", {
method: "POST",
headers: {"Content-Type": "application/x-www-form-urlencoded"},
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: process.env.FEDEX_CLIENT_ID,
client_secret: process.env.FEDEX_CLIENT_SECRET
})
});
const { access_token } = await tokenResp.json();
Many integrations fail because the server is bound to localhost instead of 0.0.0.0. Replit exposes web servers publicly only if they listen on 0.0.0.0. If you use FedEx webhooks (e.g., for shipment status updates), the webhook URL will not reach your app unless your webhook listener runs on the correct host and port.
// Express server listening correctly for FedEx webhook
import express from "express";
const app = express();
app.post("/fedex/webhook", express.json(), (req, res) => {
console.log(req.body);
res.sendStatus(200);
});
app.listen(3000, "0.0.0.0"); // Must be 0.0.0.0 for Replit to expose port
FedEx webhooks include verification steps or security headers that confirm messages are from FedEx. Many developers skip verifying and just accept all incoming POST requests. This is unsafe. Always validate the X-FedEx-Signature or token you configured in their Developer Portal to ensure authenticity.
// Simple FedEx webhook validation example
if (req.headers["x-fedex-signature"] !== process.env.FEDEX_WEBHOOK_SECRET) {
return res.sendStatus(403); // Unauthorized
}
Replit servers pause when idle or restart after inactivity. Treat Replit as a development or lightweight integration runtime, not as always-on backend. FedEx APIs require stable callbacks and tokens. For production, move webhook or long-running processes to a persistent host, and keep Replit focused on testing, debugging, or UI integration layers.
# Using Replit Workflows to start a FedEx poller safely
replit workflows run start_fedex_poller
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. Weâll discuss your project and provide a custom quote at no cost.Â