FROM CACHE - en_header

Shopify refund API

Alexander_Dzhus
Shopify Partner
11 0 0

Hello, I am trying to make simple refund notification via this API (https://help.shopify.com/api/reference/refund)
A lot of products don't have shipping, so I just want to send refund amount in the request.

So I make a POST request on this address: https://payment-gatreway-trial.myshopify.com/admin/orders/4201820099/refunds.json
with autorization and this body:

{
  "refund": {
    "transactions": [
      {

        "amount": "20.65",
        "kind": "suggested_refund",
        "gateway": "BlueSnap",
        "parent_id": 801038806
      }
    ]
  }
}

And I get: 404 Not Found.

I am sure that URL and authorization are correct, because I can make GET request, result is: {"refunds":[]}

Where is a problem ?

And One more question, what is "parent_id" and where can I get it, because usedone is taken from the example (in the URL) ?

Replies 6 (6)
Jordan
Shopify Staff
Shopify Staff
300 3 75

Hey Alexander,

It looks like the problem is that you're referencing a transaction that doesn't exist. The parent_id is from the Transaction resource and is referring to the ID of a previous transaction (i.e a transaction that captures a payment has a parent_id with the same value of the id of the original transaction that authorizes the payment). Keep in mind that when creating a Refund, you're simply creating a record of the refund that may include a Transaction that was the result of an exchange of money.  

 

- Jordan

Jordan | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Alexander_Dzhus
Shopify Partner
11 0 0

Ok, I made additional request to get  the parent_ID (4603014019) , used it in my refund request, and get another error now:

" {"errors":{"base":["Order cannot be refunded"]}} " (Response code: 422 - Unprocessable Entity ) ?

By the way, I made request to the ".../refunds/calculate.json" with the same body, and got "{"refund":{"shipping":{"amount":"0.00","tax":"0.00","maximum_refundable":"0.00"},"refund_line_items":[],"transactions":[]}}".

Please, advice what should I fix  this time ? Can it happens because it is a TEST order ?

Also here is data of the initial transaction, just in case :

"
{"transactions":[{"id":4603014019,"order_id":4201820099,"amount":"141.60","kind":"sale","gateway":"bluesnap","status":"success","message":"Completed","created_at":"2016-11-25T07:37:58-05:00","test":true,"authorization":"1013030293","currency":"EUR","location_id":null,"user_id":null,"parent_id":null,"device_id":null,"receipt":{"x_account_id":"api_adzhus","x_amount":"141.60","x_currency":"EUR","x_gateway_reference":"1013030293","x_reference":"9647814531","x_result":"completed","x_test":"true","x_timestamp":"2016-11-25T15:37:55Z","x_signature":"104cab34c2dbaf495d5a85589e9605b4af581bf981e3667bbbe4b1f6b9d33ef2"},"error_code":null,"source_name":"web"}]}"

Alexander_Dzhus
Shopify Partner
11 0 0

Does anybody here ?

Jordan
Shopify Staff
Shopify Staff
300 3 75

Hey Alexander,

If you're creating a Refund, you may have to attach other fields in your request as well. See here

Can you try that and let me know your results? 

 

- Jordan

 

- Jordan

Jordan | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Alexander_Dzhus
Shopify Partner
11 0 0

Hello, Jordan, here is what I tried and what I got.

1.  

{
  "refund": {
    "restock": true,
    "notify": true,
    "note": "wrong size",
    "transactions": [
      {
        "parent_id": 4672584259,
        "amount": "2.65",
        "kind": "refund",
        "gateway": "bluesnap"
      }
    ]
  }
}

Result: 422 Unprocessable Entity. Message: {"errors":{"base":["Order cannot be refunded"]}}

 

2. (however this product doesn't have shipping )

{
  "refund": {
    "restock": true,
    "notify": true,
    "note": "wrong size",
 "shipping": {
      "full_refund": true
    },

    "transactions": [
      {
        "parent_id": 4672584259,
        "amount": "2.65",
        "kind": "refund",
        "gateway": "bluesnap"
      }
    ]
  }
}

Result: 422 Unprocessable Entity. Message: {"errors":{"base":["Order cannot be refunded"]}}

 

3. (I don't really understand what is refund_line_items  and where can i find its ID, so I took a default from your example )

{
  "refund": {
    "restock": true,
    "notify": true,
    "note": "wrong size",
 "shipping": {
      "full_refund": true
    },
 "refund_line_items": [
      {
        "line_item_id": 518995019,
        "quantity": 1
      }
    ],
    "transactions": [
      {
        "parent_id": 4672584259,
        "amount": "2.65",
        "kind": "refund",
        "gateway": "bluesnap"
      }
    ]
  }
}

Result: 422 Unprocessable Entity. Message: {"errors":{"refund_line_items.line_item":["can't be blank"],"refund_line_items.quantity":["cannot refund more items than were purchased"]}}

GregSmithRR
Shopify Partner
15 0 5

I'm also getting a 422 when passing an empty array for transactions. Can you not "refund" a $0.00 Order? I want to be able to refund and restock...inventory management.