422 Unprocessable Entity when trying to calculate refund

Solved
stefanBerlin
New Member
2 1 0

Hello,

 

I am failing while sending a post request to the calculate refund endpoint. I use the "@shopify/shopify-api" module as described in the documentation and the code as follows:

 

 

 

 

const ShopifyOuter = require("@shopify/shopify-api/dist/index")
const { Shopify, DataType } = ShopifyOuter

const client = new Shopify.Clients.Rest(
  `${process.env.SHOPIFY_STORE}.myshopify.com`,
  process.env.SHOPIFY_SECRET
)

const calculateData = await client.post({
        path: `orders/4576716390624/refunds/calculate`,
        data: {
          refund: {
            shipping: { full_refund: true },
            refund_line_items: [
              {
                line_item_id: 42035992527072,
                quantity: 1,
                restock_type: "no_restock",
              },
            ],
          },
        },
        type: DataType.JSON,
      })

 

 

 

 

All I get as a response is this:

 

 

 

 

{ "code": 422, "statusText": "Unprocessable Entity" }

 

 

 

 

From this, I cannot figure out what the error is. I checked all these things:

  • the env variables are existing and are accessible from the script (some of them are only replacement for credentials I don't want to show)
  • the order id is existing, not archived, not cancelled, not returned, not refunded, and it belongs to this store
  • the order consists of the single product given in the refund_line_items
  • line_item_id and quantity are numbers, no strings
  • there is no difference between passing the value of the data property as a JavaScript object and as a JSON object (using JSON.stringify)

 

Can somebody help me to get on the right track. I appreciate any help from your side.

 

Stefan

Accepted Solution (1)

Accepted Solutions
stefanBerlin
New Member
2 1 0

This is an accepted solution.

Hello again,

 

I finally managed it to find the reason for the failure. The line_item_id I have to provide is something I have to take from the original order data. It is neither the product ID nor the variant ID which is usually taken for checkout links.

 

I visualized the response of a request for a certain order to make clear, which ID to use.

 

{
  "line_items": [
    {
      "id": xxxxxxxxx       <-- This is the ID to use to describe a returned product!
    }
  ]
}

 

Thank you for your help although no one found the solution to my problem before me.

 

Stefan

View solution in original post

Reply 1 (1)
stefanBerlin
New Member
2 1 0

This is an accepted solution.

Hello again,

 

I finally managed it to find the reason for the failure. The line_item_id I have to provide is something I have to take from the original order data. It is neither the product ID nor the variant ID which is usually taken for checkout links.

 

I visualized the response of a request for a certain order to make clear, which ID to use.

 

{
  "line_items": [
    {
      "id": xxxxxxxxx       <-- This is the ID to use to describe a returned product!
    }
  ]
}

 

Thank you for your help although no one found the solution to my problem before me.

 

Stefan

View solution in original post