Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for tracking multiple packages #11

Open
NetRxn opened this issue Sep 1, 2020 · 1 comment
Open

Support for tracking multiple packages #11

NetRxn opened this issue Sep 1, 2020 · 1 comment

Comments

@NetRxn
Copy link

NetRxn commented Sep 1, 2020

Thanks for an awesome package!

Since the USPS API can handle up to 35 tracking IDs per request, i'm wondering if there's a good way to pass a list with your existing package, or if it would be possible to add this feature.

I tried to generate the URL string using variations of the code below, but I lost the detailed dictionary that your single query code provides.

{'EventTime': '
'EventDate':
'Event':
'EventCity':
'EventState':
'EventZIPCode':
'EventCountry':
'FirmName':
'Name':
'AuthorizedAgent':
'DeliveryAttributeCode': },

-----------------------------------what I tried --------------------------------------------------

def USPSRequest(trackingNumbers,userID):

TrackingNumbersFormatted = f'<TrackRequest USERID="{userID}">'
TrackingNumbersFormatted = str(TrackingNumbersFormatted)
for i in trackingNumbers:
    TrackingNumbersFormatted += "<TrackID ID="
    TrackingNumbersFormatted +='"'
    TrackingNumbersFormatted += str(i).strip()
    TrackingNumbersFormatted +='"></TrackID>'

URL = f'https://secure.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML={TrackingNumbersFormatted}</TrackRequest>'.replace('&amp;','&').replace('&lt;','<')
#return URL 
        
xml_response = requests.get(URL).content
response = json.loads(json.dumps(xmltodict.parse(xml_response)))
if 'Error' in response:
    raise USPSApiError(response['Error']['Description']) 
return response

I'm fairly new to APIs & XML so I'm sure there's a much more elegant way to do this.

Thanks again, and have a great night!

@Robert-Muil
Copy link

I've added this capability to the CityStateLookup API in this PR: #13. Should be very easy to do the same thing for the tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants