EasyPost/easypost-php

Tracker create_list function

Closed this issue · 4 comments

Hi! I'm trying to understand how the create_list() function works in order to do a batch tracker creation.

The example var_dump() in https://github.com/EasyPost/easypost-php/blob/master/examples/tracker_batch_create.php returns null, as it does when I use create_list() myself. The docblock says it returns mixed, but there is no return statement.

public static function create_list($params = null, $apiKey = null)

Hey @neodisco, the create_list endpoint does not return anything but does work as intended. I was able to test this on our end and saw these trackers created on the backend using the example script found in this repo. You'll want to capture these creation events via webhook as this endpoint does not return a response or you can create trackers individually to get that response immediately.

Thanks Justin! Your commit does clarify it an order of magnitude. What do you think about the logic that it returns null regardless of whether each tracker creation was a success or a failure? If you then have to check them individually to see if they succeeded with another request, for what purpose would you recommend me using the create_list function as opposed to just creating them individually? I'd be using the list_create function to avoid making multiple requests in lieu of the EasyPost API returning rate limiting data and having to just "sleep(1)" in the hopes I don't trigger a 429.

The create_list endpoint is a bit wonky and as such isn't documented and is only present in 1 or 2 of our client libraries. It's great for sending large lists of tracking codes to be created in EasyPost; however, it comes with its drawbacks as you are seeing. The API itself doesn't return anything as it works through the queue asynchronously, as such, there is not really any logic that we can correct in the client library to ensure these were received or not as doing so wouldn't return anything from the API.

It ultimately depends on your workflow and how many you have. If you have dozens of tracking codes, it may be better to simply iterate your list and create them individually if you want to see that response immediately. If you have hundreds or thousands, that obviously doesn't scale well and you'd instead want to try the create_list endpoint. As for rate limiting, it's certainly a concern, but you can do a few a second and still be fine to speed up your process.

Got it! Thanks a lot Justin.