Any way to partially refund an order via API without specifying a line item?

Solved
RareArtifact
Tourist
11 0 2

When you view an order in the Shopify admin, the option exists to give a partial refund without making any changes to the order or choosing a specific item the refund is for. It looks like this:

RareArtifact_0-1616702207877.png

I want to do exactly this, but through the API. It seems the refunds object requires a line item or shipping to be specified. The refund I want to do has nothing to do with a specific item or shipping, and should be generically applied to the entire order just like how it works when you use the window above. No status change, no correlation to item or shipping.

Is there any way to do this?

 

syf_
Shopify Staff
Shopify Staff
89 20 15

This is an accepted solution.

@RareArtifact I believe you can achieve this with the following code snippets.

GraphQL

mutation RefundCreate($input: RefundInput!) {
  refundCreate(input: $input) {
    refund {
      id
      totalRefundedSet {
        presentmentMoney {
          amount
          currencyCode
        }
      }
      transactions(first: 100) {
        edges {
          node {
            id
            status
            kind
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

Query Variables
{
  "input": {
    "orderId": "gid://shopify/Order/{order_id}",
    "currency": "CAD",
    "note": "Overpaid",
    "transactions": {
      "amount": "3",
      "kind": "REFUND",
      "gateway": "shopify_payments",
      "orderId": "gid://shopify/Order/{order_id}",
      "parentId": "gid://shopify/OrderTransaction/{transaction_parent_id}"
    }
  }
}

 

REST

POST /admin/api/2021-04/orders/{order_id}/refunds.json
{
  "refund": {
    "currency": "CAD",
    "note": "Overpaid",
    "transactions": [
      {
        "parent_id": {transaction_parent_id},
        "amount": 3.0,
        "kind": "refund",
        "gateway": "shopify_payments"
      }
    ]
  }
}

 

Best,
Seth.

syf_ | 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

0 Likes
RareArtifact
Tourist
11 0 2

This was exactly what I needed, thanks!

0 Likes