FEDEX API tracker using Python

Viewed 39

I have been working on a FedEx tracking API program in Python. I have what I think to be the right code and I have already registered and gained access through FedEx to use the API keys and so on. I am having difficulty finding what packages/libraries to install and then import to be able to run my program. Here is what I have.

from fedex.config import FedexConfig

CONFIG_OBJ = FedexConfig(key='<key>',
                     password='<pass>',
                     account_number='<acct_no>',
                     meter_number='<meter_no>')

from fedex.services.track_service import FedexTrackRequest

track = FedexTrackRequest(CONFIG_OBJ)
tracking_num = '781820562774'

track.SelectionDetails.PackageIdentifier.Type = 
'TRACKING_NUMBER_OR_DOORTAG'
track.SelectionDetails.PackageIdentifier.Value = tracking_num
track.SelectionDetails.PackageIdentifier.CarrierCode = 'FDXG'  #G 
for ground FDXE for express
track.send_request()

print(track.response)
1 Answers

to use API's you should use the requests and json libraries

if you don't have the requests library, simply use pip install requests

here's a simple example:

import requests
import json


fedex = requests.get ("URL")
fedex_api = fedex.json()

Related