Hi All,
I would appreciate if you could please help me with an Issue, I am not a shopify developer, instead an ERP developer trying to integrate Shopify with RestAPI.
User Case: Customer wants to integrate Draft Orders in ERP. DraftOrder created in shopify, it pulled into ERP using the draft_order API. So far so good. Now, the draft orders are being reviewed in ERP, lines can be added, alternate Variants might be suggested and once completed in ERP, Draft Order is pushed back to shopify and marked as complete.
Issue: Draft order created with 3 Lines on shopify and pulled into ERP as it is. Now, one of the variant is not available for various reasons and B2B customer has agreed for it to be replaced with a different variant.
How do I delete a line in the draft order API ?
This works fine
However, when tried to update back to update a line with Zero Quantity and send back another variant it sends the following error. Just adding a new line item works, reducing quantity to zero of an existing one doesn’t delete the line.
How can we delete a line item from a draft order ?
Many thanks
hello there
To delete a line item from a draft order using the Shopify Draft Order API, you can make a DELETE request to the specific line item URL with the line item ID included in the URL.
Here is an example of the endpoint you would use to delete a specific line item:
DELETE /admin/api/2021-07/draft_orders/{draft_order_id}/line_items/{line_item_id}.json
- To delete a line item, you would replace “{draft_order_id}” with the ID of the draft order that contains the line item you want to delete, and “{line_item_id}” with the ID of the line item you want to delete.
- Here is an example of how you could make the request to delete a line item in Node.js:
const request = require('request');
const options = {
method: 'DELETE',
url: 'https://your-store.myshopify.com/admin/api/2021-07/draft_orders/{draft_order_id}/line_items/{line_item_id}.json',
auth: {
user: 'your-api-key',
password: 'your-api-password'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Replace “your-store” with your Shopify store name, and “{draft_order_id}” and “{line_item_id}” with the appropriate values.
To delete a line item from a draft order using the Shopify Draft Order API, you can send a PUT request to the API endpoint for the draft order and include the line item ID of the line item you want to delete in the request body.
Here’s an example of the PUT request you could use to delete a line item:
PUT /admin/api/2022-01/draft_orders/{draft_order_id}.json
{
“draft_order”: {
“line_items”: [
{
“id”: “{line_item_id}”,
“_destroy”: true
}
]
}
}
In this example, you would replace {draft_order_id} with the ID of the draft order you want to modify, and {line_item_id} with the ID of the line item you want to delete.
To delete the line item, you would set the _destroy property for the line item to true in the request body. This tells the Shopify API to delete the line item from the draft order.
Once you have sent this PUT request, the line item should be removed from the draft order in Shopify.
Thanks for the suggestion, when I try that, I get the same issue
Thanks for the suggestion, However, that doesnt seem to be working, attached screenshot
Draft order for ID and Line ID’s
Now, i am trying to make a DELETE request using the DraftOrderID and the LineID. Server rejects the request