AfterShip/aftership-sdk-python

get_tracking for postnl-3s courier

evoloshchuk opened this issue · 7 comments

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.`

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)

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).

@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"
        ],
...

@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

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

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.

Any progress on this issue? Thanks.