shippo

How do I purchase a label with Shippo via the Stripe integration?


I'm looking to integrate Shippo with Stripe to get shipping rates for my shop, and I want to purchase the label through Shippo.

Getting the rate from Shippo via the Stripe API is fine, then I make a call for the Rate using the object_id from the Stripe results.

But when I try to purchase the label through the Transaction request on from Shippo API, it says that it's rejected because it's a QUOTE, not a PURCHASE rate.

Here's the error message: "The given Rate can't be purchased because it's object_purpose is not PURCHASE."

How do I convert the Rate from a QUOTE to PURCHASE?


Solution

  • Right now you can't convert a Rate from QUOTE to PURCHASE on Shippo, so you'll have to create a shipping label through Shippo with the single-call label creation process. You can pass in the carrier and service level tokens that you got from the Rate response to get what you need.

    See the full Shippo label generating example with Stripe. Here are the snippets you'll want to note:

    # create Label with one API call - carrier_account, and servicelevel_token taken from the rate response.
    
    transaction = shippo.Transaction.create(
        shipment = shipment,
        carrier_account = rate.carrier_account,
        servicelevel_token = rate.servicelevel_token