0

I am using the console command to delete an order item so I need also to create a credit memo based on the delete item price and refund the payment to the customer online using API.

I used the following API to credit memo of particular order ITEM based on the order ID:

ENDPOINT: https://dev.com/rest/V1/invoice/{Invoice ID}/refund

{
  "items": [
    {
      "order_item_id": {Order Item ID},
      "qty": 1
    }
  ],
  "notify": true,
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        1
      ]
    }
  }
}

When I send the API request it is throwing an issue of

  {
        "message": "Creditmemo Document Validation Error (s): \ n The back-to-warehouse argument contains a product item that is not part of the original order.",
        "trace": "# 0/home/dev/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Sales\\Model\\RefundInvoice->execute(91371, Array, false, true, false, NULL, Object(Magento\\Sales\\Model\\Order\\Creditmemo\\CreationArguments))\n#1
/home/dev/public_html/pub/index.php(28): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#15 {main}"
    }

Can you please help me with how to create a credit Memo using API of a particular order?

3
  • "I am using the console command to delete an order item" - can you elaborate? As per my understanding you have actually removed an item from an order and are now trying to refund that very same - but forcefully deleted - item. If so, to me the only viable solution that comes to my mind is that you should try and get back that item into your order (database) so you can properly refund it then (your accountant most like will appreciate this as well as you seem to have invoices and refunds that just don't add up otherwise... ;)) Jan 10, 2022 at 23:36
  • Do I have to create a credit memo of that particular item firstly before deleting that item from an order using the custom command line? php bin/magento order:deletecommand <Order increment ID>,<Order Item ID> Once admin will add increment ID and order item ID with comma-separated then order Item id will delete in the order backend. Jan 11, 2022 at 8:26
  • I don't think you're supposed to delete an item from the order at all, why would you want to delete it? The item in that order will have the state 'refunded' whilst the other items than will become shipped. Jan 11, 2022 at 13:12

1 Answer 1

0

If, as you wrote, already deleted order item, then you can not refund that order. There is tables sales_order and sales_order_item. In sales_order_item there is order items (that as you say deleted). So order do not have order items anymore. And without order items, you won't be able to create credit memo. That error part tell you that already

The back-to-warehouse argument contains a product item that is not part of the original order.

I don't know why you delete item first. Do not do that. Just create credit memo and magento will do rest.

4
  • I understand what you want to say exactly. When we create the credit memo for the particular item then Magento deletes that order item automatically. Please correct me if I am wrong here Jan 11, 2022 at 8:23
  • No, order should have order items. Why delete it? Refund is not like you delete items. Jan 11, 2022 at 9:36
  • My requirement is to delete the order Item and refund based on the amount of the deleted item. Jan 11, 2022 at 9:40
  • Why delete? What it gives you? If you delete it, you won't be able to refund, simple as that. Order won't have order items to refund, so it is not possible. Do refund and then delete then, but I do not see point to delete it. You give magento order, order items, it does refund and no need to delete it. What you want to gain with that delete? Jan 11, 2022 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.