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

get_tracking for postnl-3s courier #23

Closed
evoloshchuk opened this issue Sep 7, 2020 · 7 comments · Fixed by #26
Closed

get_tracking for postnl-3s courier #23

evoloshchuk opened this issue Sep 7, 2020 · 7 comments · Fixed by #26

Comments

@evoloshchuk
Copy link

evoloshchuk commented Sep 7, 2020

Postnl-3s courier requires tracking_destination_country and tracking_postal_code to be specified to retrieve a tracking.
However, currently it's not possible to specify those via aftership.tracking.get_tracking method (it only allows for the optional_keys to be passed along).

Details:
aftership.tracking.get_tracking(slug="postnl-3s", tracking_number="XYZ")
throws
aftership.exception.BadRequest: BadRequest: \'tracking_destination_country\' is required.
and then (once the first one is hacked in)
aftership.exception.BadRequest: BadRequest: \'tracking_postal_code\ is required.`

@alviezhang
Copy link
Member

alviezhang commented Sep 25, 2020

You need to create tracking first before you want to get a tracking. For example,

from aftership import tracking

response = tracking.create_tracking(tracking={
    "slug": "postnl-3s",
    "tracking_number": "abcxyz",
    "tracking_destination_country": "USA",
    "tracking_postal_code": "12345"
})

tracking_id = response["tracking"]["id"]
tracking_response = tracking.get_tracking(tracking_id=tracking_id)
print(tracking_response)

@evoloshchuk
Copy link
Author

Thank you for your reply @alviezhang, but that does not help my case.
I need to look up a tracking by its slug & tracking_number - not by its tracking_id. This works for some couriers, for example for postnl, dhlparcel-nl, dhl-germany, but not for postnl-3s (because of the reasons I explained above).

@alviezhang
Copy link
Member

alviezhang commented Oct 12, 2020

@evoloshchuk Some couriers require users must specify some fields when create a tracking. You can check it in the official document https://docs.aftership.com/api/4/couriers/get-couriers.

From my side, I can get these information from the couriers API:

...
     "required_fields": [
          "tracking_destination_country",
          "tracking_postal_code"
        ],
...

@evoloshchuk
Copy link
Author

@alviezhang the problem is not to figure out what fields are required to create a tracking (that part works), but to retrieve such tracking afterwards without tracking_id.

tracking.get_tracking methods support look up by slug & tracking_number, which is not enough in the case when additional fields are required - and there is no way to pass those additional parameters.

So, for postnl-3s case
tracking.get_tracking(slug="postnl-3s", tracking_number="XYZ")
throws an exception, because the courier expects more parameters.
Something like this should work - but the method does not support such parameters.
tracking.get_tracking(slug="postnl-3s", tracking_number="XYZ", tracking_destination_country="BEL", tracking_postal_code="1234")

Hence my request is to make it possible to specify tracking_number & tracking_destination_country for the tracking.get_tracking method.

Hope it's clear.
Thanks

@alviezhang
Copy link
Member

@evoloshchuk Understood. This is an API behavior, I need to confirm with the relevant colleagues.

@alviezhang
Copy link
Member

alviezhang commented Oct 13, 2020

As you can see, the Pro tips in https://docs.aftership.com/api/4/trackings/get-trackings-slug-tracking_number shows

You must pass other required parameters `tracking_*` if a courier requires such information when the tracking is created.

The unique key we locate a tracking is slug, tracking_number and any other required fields.

Most of couriers has no other required fields, so you can get the tracking through slug and tracking number.

For slug postnl-3s, tracking_destination_country and tracking_postal_code is required field, so you have to pass them as query parameters.

This is an API design issue, we should not treat tracking_number as the only resource identifier, we may optimize this in the next version of API.

@Tezzlicious
Copy link

Any progress on this issue? Thanks.

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