Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Re:

Refund amount from order via API

Freddie_Lawson
Shopify Partner
10 0 3

Hello

 

Is there a way to issue a partial refund of a customer's order via API? In the UI it would simply be done using the input, into which an arbitrary value can be entered. According to the docs here, it seems like this is not possible via the API, and the only way is to build a list of refund_line_items. Am I correct here?

 

Many thanks

 

Screenshot 2023-02-24 at 15.12.04.png

 

Replies 6 (6)

garyrgilbert
Shopify Partner
431 41 186

Hi there shopify.dev is your friend 🙂

 

https://shopify.dev/docs/api/admin-rest/2022-04/resources/refund

 

Check out the examples

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Freddie_Lawson
Shopify Partner
10 0 3

Hi Gary

 

Yeh had already consulted docs, unfortunately at a dead end though. I've worked out it's necessary to create a transaction first, and then you pass that transaction object in when creating the refund. 

 

All prior steps seem fine and the transaction is creating correctly, however, when making the final call to create the refund with the below payload, I am returned the error 422 error - "An error occurred while processing your request"

 

 

{
    "refund": {
        "notify": true,
        "transactions": [
            {
                "kind": "refund",
                "amount": 10.12,
                "gateway": "shopify_payments",
                "currency": "GBP",
                "parent_id": 6382484750500
            }
        ]
    }
}

 

 

garyrgilbert
Shopify Partner
431 41 186

Hey there,

 

My workflow would be as follows:

1) call calculate refund for the order id that you want to return, leave the refund_line_items blank

- you will get back a refund object with an array of transactions - amount will probably be 0

- modify the transaction object and change the kind from "sugested_refund" to "refund"

- modify the amount to the fixed amount that you want to refund e.g. 10.12

2) call the create refund endpoint with the modified refund structure from step one

3) go for a pint cause you are done.

 

Cheers,

 

Gary

 

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
PurpleMamba
Shopify Partner
126 1 18

I was really hoping this would work but unfortunately just get nil for transactions back from the refund calculate step.

wgerven
Shopify Partner
1 0 0

Hi @PurpleMamba for me Gilbert's suggestion worked for sure.

garyrgilbert
Shopify Partner
431 41 186

This will only work on an order that is paid, if the financial_status is pending and/or the order was created via the admin as of April (I think) then the original order has no transactions until the order has been marked as paid.

 

Also again, a refund can only be issued for an oder that has been paid 🙂

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution