goshippo / shippo-php-client

Shipping API PHP library (USPS, FedEx, UPS and more)
https://goshippo.com/docs
MIT License
161 stars 88 forks source link

Cannot Consistently Retrieve Shipping Rates. #88

Open ma077146 opened 1 month ago

ma077146 commented 1 month ago

We are using shippo/shippo-php v1.5 installed via composer to actually make the API calls to Shippo.

Once we have all pertinent information, we make a call to Shippo via /vendor/shippo/shippo-php/lib/Shippo/Shipment.php create method, which in turn calls _scopedCreate() in abstract class Shippo_ApiResource class.

The returned Shippo Object is used to store what we call the “shipment_id” in our database.

Next, we make a call to the Shippo API with that “shipment_id” from above via /vendor/shippo/shippo-php/lib/Shippo/Shipment.php get_shipping_rates() function,

which uses the Shippo_ApiResource _scopedGet() method to return the rates to us.

The code on our side that calls the Shippo API is wrapped in a try/catch block. That is where the below error is from:

Unable to retrieve shipping rates for shipment ID: d94f493a0c304f14b99c0f583e398f68 | cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.shipengine.com/v1/carriers

Everything in the above error starting with “cURL” is the exception from the catch block.

We flash a message at the top of the page that says, “Unable to retrieve shipping rates. Please reload the page to try again.“ which could be why some of the shipping object id numbers we have sent can be associated with rates that were fetched and returned.

Making the exact same API calls, there are two other variations of the errors we see when trying to retrieve shipping rates.

Unable to retrieve shipping rates for shipment ID: ff8f884fe6e14c44a4078c9e91741e1e | Trying to access array offset on value of type null

Unable to retrieve shipping rates for shipment ID: 678c0f65d6674bc2ab233c1ef2b78ea9 | Undefined array key "carriers"

These issues occur in bunches. We haven’t seen any since July 29, 2024, but between June 7, 2024 and July 29, 2024 we’ve had 268 such errors. That doesn’t sound like a lot, but it brings shipping to a halt, and the pharmacy is forced to log into UPS and FedEx via browsers to get shipping done, which greatly disrupts their work flow.

The pharmacy can have as many as 8 to 10 different people working on shipments during the day. Do you know if we are limited to making a certain number of requests within a given time period?

assislucas commented 1 month ago

Hi @ma077146 it looks like you are using https://api.shipengine.com/v1/carriers as the API URL with this SDK, the Shippo API base URL should be https://api.goshippo.com.

Can you please share if you still see the same error with the correct Shippo base URL?

Thank you!

ma077146 commented 1 month ago

Will try as soon as I get a few fires put out.

ma077146 commented 1 month ago

@assislucas I have some more information. When this project was originally completed, Shippo could not provide an estimated delivery date (example 27 November, 2024 instead of 2 days from now). Since ShipEngine could, we create the shipment with Shippo, but request rates from ShipEngine.

In the image, $rate is rates returned from ShipEngine, and the snippet below shows the estimated delivery date for that carrier/rate.

image

Is there an SDK call for Shippo that will return the estimated delivery date? For example, if I choose 2 day shipping from UPS for a shipment created today, the 7th of August, can I get "9 August, 2024 returned from Shippo?

If so, that's an easy fix for us.

assislucas commented 1 month ago

@ma077146 thanks for the additional context. As of this now Shippo does not have an estimated_delivery_date field in our rates, but this is actually part of our short term roadmap, in fact we intend to work on it next month and release some time in November for UPS as the first carrier, and later this year for FedEx and USPS.

If you are generating rates from ShipEngine and want to use Shippo to purchase labels you can still do that. If you share your code snippet that you are using for generating Shippo rates I would be happy to help you debug that.

Also, if you prefer to debug this live feel free to email me lucas@shippo.com and we can set up some time to fix this for you. Thank you.

ma077146 commented 1 month ago

Lucas, thank you for the fast response.

I've asked my production team to consider allowing me to take the "estimted_days" value Shippo provides, and use that to calculate the estimated delivery date based on the shipping date. I'm sure they can see how I can make that leap! I have no doubts that ShipEngine is doing the same thing.

In their response, they return "delivery_days" and "estimated_delivery_date" values. So we just use the later instead of calculating based on the number of days.

It is my understanding that there are some days which don't count towards shipment time for the carriers, so it's not as easy as choosing the date 2 days from now. If I ship on a Friday, two days doesn't mean Sunday in every case, so I better understand why they want to use that value.

If I find any more information, I'll be glad to share here. Thank you again for your help and fast responses.

assislucas commented 1 month ago

@ma077146 Of course, glad I could be of help. Don't hesitate to reach out through here or email if you need any additional assistance.