Checkout API: Adding line item properties when creating new Checkout?

benfarhner
Tourist
10 0 14

I'm trying to add line item properties when creating a new Checkout object using the Checkout API for my sales channel app, and it doesn't appear to be working. It's not clear what format the checkout.line_items.properties property is expecting or whether it can even be set when creating a Checkout object:

The Checkout API documentation (https://shopify.dev/api/admin/rest/reference/sales-channels/checkout) states that checkout.line_items is required, and defines the properties property on each line_item as "The customization information for a line item (optional)." (emphasis mine). So this looks like it should be something I can set when creating a Checkout object. The POST example doesn't show setting the line item properties, but it does show that property in the response as an object:

 

"line_items": [
  {
    // ...
    "properties": {},
    // ...
  }
]

 

In the description above, "customization information" actually links to the Liquid docs (https://shopify.dev/api/liquid/objects/line_item#line_item-properties), which I found strange. The Liquid documentation states that line_item.properties is an array, and the example makes it appear like it's actually an array of arrays of properties, e.g.:

 

[
  [ 'key', 'value' ],
  [ 'foo', 'bar' ]
]

 

I have tried setting properties on line items when creating a new Checkout object through the Checkout API with multiple different formats at this point, but the returned Checkout object always has an empty object on each line item:

 

// This doesn't work:
line_item.properties = { 'foo': 'bar' };

// This doesn't work either:
line_item.properties = [ 'foo', 'bar' ];

// Nor this:
line_item.properties = [
  [ 'foo', 'bar']
];

// Nor this:
line_item.properties = [
  { 'foo': 'bar' }
];

// All of them come back like this in the response:
"line_items": [
  {
    // ...
    properties: {},
    // ...
  }
]

 

So I have 3 questions:

  1. Is it possible to set the line item properties on a line item when creating a new Checkout object through the Checkout API?
  2. If it is possible, what structure should line_item.properties have?
  3. If it's not possible through the Checkout API, what other options do I have for setting line item properties programmatically?

My goal here is to get some kind of unique information in the payload that gets sent to my app's Carrier Service. There is not a lot of information passed to the CarrierService's callback_url, but it does include properties for the items, so I'm hoping to take advantage of that if at all possible.

And ultimately the reason I'm trying to do that is because I want my Carrier Service rate to only appear in my sales channel. By filtering on line item properties, I can only return rates when a certain flag is set, and otherwise return no rates. If there's another way to achieve this, I'm open to ideas there as well.

Thanks,
Ben

Replies 6 (6)

benfarhner
Tourist
10 0 14

Bump on this as it's a very pressing business need for our sales channel. Is there a way to do this with the Checkout API?

benfarhner
Tourist
10 0 14

I also tried this structure to no avail:

 

line_item.properties = {
  {
    "name": "_pebble",
    "value": "true"
  }
};

 

Any ideas? Surely someone has done this (or attempted to do this) before.

benfarhner
Tourist
10 0 14

Bump again. A week with no responses? Neither Shopify nor any other devs have any feedback one way or another on what I'm trying to accomplish here? 😞

benfarhner
Tourist
10 0 14

Bump again, a month later. I would love to hear back from the Shopify team on this question. Surely someone has tried to accomplish this before!

get4137
Shopify Partner
4 0 1

I used storefront api: https://shopify.dev/api/storefront/2022-01/mutations/checkoutlineitemsreplace
But I think it should work the same way

:lineItems => {

:customAttributes => [{:key => "some_key", :value => "some_value"



And than you will get something like this in checkout object:
lineItems => "properties":[{"name":"some key","value":"some value"}]

Bengk
Shopify Partner
21 0 13

Same issue. Anybody figure this out?