BUG: Adding Properties to Draft Order via REST API

New Member
6 0 0

I've run into a bug with the REST API, it doesn't allow me to add properties to a line item when creating a draft order. I tested this out in the GraphQL API and although properties are renamed to customAttributes it accomplishes what I want. Here is the GraphQL call I'm trying to mimic in the REST API

mutation ($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
      lineItems(first: 1) {
        edges {
          cursor
          node {
            id
            name
            customAttributes {
              key
              value
            }
          }
        }
      }
      customer {
        id
        firstName
        lastName
      }
    }
  }
}


{
  "input": {
  	"lineItems": {
    	"variantId": "gid://shopify/ProductVariant/12456079654978",
    	"quantity": 1,
    	"customAttributes": {
      	"key": "when",
      	"value": "RIGHT NOW!!"
    	}
  	},
  	"customerId": "gid://shopify/Customer/564408418370"
	}
}

Here is all the different variations I have tried in the REST API to no success at getting a properties set

await shopifyApi.draftOrder.create({
    line_items: {
        variant_id: item.variantId,
        quantity: item.quantity,
        customAttributes: {
            key: "when",
            value: item.properties.when,
        }
    },
    customer: {
        id: 564408418370
    }
});
await shopifyApi.draftOrder.create({
    line_items: {
        variant_id: item.variantId,
        quantity: item.quantity,
        customAttributes: [{
            key: "when",
            value: item.properties.when,
        }]
    },
    customer: {
        id: 564408418370
    }
});
await shopifyApi.draftOrder.create({
    line_items: {
        variant_id: item.variantId,
        quantity: item.quantity,
        properties: [{
            key: "when",
            value: item.properties.when,
        }]
    },
    customer: {
        id: 564408418370
    }
});
await shopifyApi.draftOrder.create({
    line_items: {
        variant_id: item.variantId,
        quantity: item.quantity,
        properties: {
            key: "when",
            value: item.properties.when,
        }
    },
    customer: {
        id: 564408418370
    }
});
0 Likes
Shopify Partner
798 75 111

hey Tim,

Do you get an error from Shopify, or it's just doesn't stick to the draft order which is created through REST API?

Sergiu

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
New Member
6 0 0

Hi Sergiu,

 

There is an error if I don’t wrap properties in an array. But the other three do not return an error and simply don’t add the properties to the draft order.

Tim

0 Likes
Highlighted