Carrier Credentials
Set up your developer accounts, obtain credentials, and authenticate with each carrier API.
For each carrier, use your Shipntel-issued account number to produce the below carrier credentials. For access to your account number, contact api@shipntel.com.
1. Get FedEx Developer Credentials
- Go to developer.fedex.com and create a developer account.
- Create a new project/app - you'll receive a Client ID and Client Secret.
- Link your FedEx shipping account number to the app for production access.
2. Get an Access Token
Tokens expire in 1 hour. Request a new one before each session or cache and refresh.
POST https://apis.fedex.com/oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
// Response:
{ "access_token": "eyJhb...", "token_type": "bearer", "expires_in": 3600 }3. Token Caching (Recommended)
Don't fetch a new token on every request, that adds latency and hits rate limits fast. Cache it in memory and only refresh when it's about to expire.
import requests
import time
# Token lives in memory for 1 hour (3 600 s). One fetch per process.
_fedex_cache = {"token": None, "expires_at": 0}
def get_fedex_token():
"""Return a valid FedEx Bearer token, fetching a fresh one only when needed."""
if time.time() < _fedex_cache["expires_at"] - 60: # 60-second safety buffer
return _fedex_cache["token"]
resp = requests.post(
"https://apis.fedex.com/oauth/token",
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
}
)
resp.raise_for_status()
data = resp.json()
_fedex_cache["token"] = data["access_token"]
_fedex_cache["expires_at"] = time.time() + data["expires_in"]
return _fedex_cache["token"]
# Use this helper anywhere you need the token:
access_token = get_fedex_token()
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}Running multiple workers? Store the token and its expiry in Redis (or any shared cache) so all instances reuse the same token instead of each fetching its own.
