Re: Carrier Service API - shipping rate request custom info

Carrier Service API - shipping rate request custom info

T_8
Shopify Partner
5 0 0

Re: Carrier Service API.

Is there anyway to get custom data from the cart page, or cart attributes, into the shipping rate request sent to the Carrier Service callback URL? Or, at the very least get the checkout token from the request?

I need to send back very specific rates under certain conditions (based on custom forms created on the cart page), without offering any other rates.

e.g.,

{
  "rate": {
    "origin": {
      …
    },
    "destination": {
      …
    },
    "items": [
      {
        …
      }
    ],
    "currency": “…”,
	“custom_note”: “a custom note added from the cart page”,
	// or
    “checkout_token”: “{token}”
  }
}

 

If I could at least get the checkout token from the request, I could (in an around and about way):

- set the specific note I need on the line_item properties on the cart page

- then when request callback comes through to the app, extract the checkout token

- use the admin api to get the checkout

- extract the property I initially set

- validate accordingly

- send the rates response

 

But, I don’t see the checkout token in the Carrier Service callback, so I can’t do that.

 

One workaround that might work:

- use the ajax api to switch the products out on the cart page to products with the same name, but different sku's, based on the customers form selections I create on the cart page

- then in the external app, validate based on the sku

But, that's an extra step of switching products out on the cart page that feels a little clunky. Any ideas or workarounds?

Cheers

T

Replies 5 (5)

Josh
Shopify Staff
1134 84 235

Hey there, 

There won't be any way to add information to the existing requests that we send - those are pre-defined on our end and aren't editable. 

At best some sort of workaround like you had mentioned above would be required here since we don't have any conventional way to accomplish this. I'll let some other developers step and share any methods they've had success with though since I haven't implemented something like this myself.

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

T_8
Shopify Partner
5 0 0

Thanks Josh, I thought that'd probably be the case. I'll have to continue on with the product switch outs I think. Thanks for the reply.

Alexey1
New Member
5 0 0

Hi T_8,

 

We have faced the same issue: needed to pass some data from cart page to CarrierService callback.

 

The only solution we found so far was this: you can write some AJAX code to add your custom data as products "line item properties" on cart page:

 

https://help.shopify.com/en/themes/customization/products/features/get-customization-information-for...

 

These "properties" will then be passed as a part of JSON request from Shopify to you CarrierService callback.

 

Hope this helps?

sebastiandev
Shopify Partner
69 1 22

I have same issue. I need cart attributes

zeeshandar
Shopify Partner
8 0 2

@T_8 I have created a custom private carrier service app on the developer portal, but no data is posted to callback_url.

I added the log and the system does hit call back url, but for some unknown reason with no shipping data.

Can you please help me with this?

The scopes I defined are:

read_shipping, write_shipping, read_checkouts, write_checkouts