Is it possible to update line_items for a draft order?

Solved
Tourist
11 2 2

I know we cannot update the line_items for an order. But is it the same case for draft order?

Or maybe using graphQL?

Thanks!

 

Request:

PUT /admin/api/2020-01/draft_orders/#{draft_order_id}.json
{
  "draft_order": {
    "id": 534088024196,
    "line_items": [
      {
        "variant_id": 32194181169284,
        "quantity": 1
      }
    ]
  }
}

Response:

{"line_items":"expected Hash to be a Array"}
0 Likes
Highlighted
New Member
2 0 0

Can anybody help, please? The response may look like a format issue but the request fields for this put API call are already an array I assume.

draft_order[id]=533752021124&draft_order[line_items][0][variant_id]=32194181169284&draft_order[line_items][0][quantity]=1

And the request-id is below.

x-request-id: 3864ebd6-cb70-494f-afc5-ada8a8537131

 

0 Likes
Highlighted
Tourist
11 2 2

This is an accepted solution.

O.K. I end up using GraphQL and it is possible. Case closed.

 

Query:

mutation draftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
  draftOrderUpdate(id: $id, input: $input) {
    draftOrder {
      id
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "id": "gid://shopify/DraftOrder/533752021124",
  "input": {
    "lineItems": [{
      "variantId": "gid://shopify/ProductVariant/32194181169284",
      "quantity": 1
    }]
  }
}

Response:

{
  "data": {
    "draftOrderUpdate": {
      "draftOrder": {
        "id": "gid://shopify/DraftOrder/533752021124"
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}
0 Likes