`return_line_items[0].quantity must be greater than 0` for GraphQL refundCreate mutation

I’m receiving the error return_line_items[0].quantity must be greater than 0 when trying to create a refund using the GraphQl refundCreate endpoint. This error is confusing to me because the field return_line_items exists nowhere on the mutation. Maybe it’s referring to the refundLineItems field? But even then, I am very clearly passing in a quantity of 1, not 0. Any ideas what’s going on here?

Hi Devin,

Can you should the full mutation (with sensitive data removed) so we can have a better view into why this mutation is generating an error?

Here’s the query:

mutation CreateRefund($input: RefundInput!) {
    refundCreate(input: $input) {
      userErrors {
        field
        message
      }
      refund {
        id
        note
        totalRefundedSet {
          presentmentMoney {
            amount
          }
        }
        transactions(first: 100) {
          edges {
            node {
              amountSet {
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
              createdAt
            }
          }
        }
        refundLineItems(first: 100) {
          edges {
            node {
              id
              subtotalSet {
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
              totalTaxSet {
                presentmentMoney {
                  amount
                }
              }
            }
          }
        }
      }
    }
  }

And the input:

{
  orderId: 'gid://shopify/Order/5852728787109',
  currency: 'USD',
  shipping: { fullRefund: false },
  notify: false,
  refundLineItems: [
    {
      lineItemId: 'gid://shopify/LineItem/14210881487013',
      quantity: 1,
      restockType: 'NO_RESTOCK'
    }
  ],
  transactions: [],
  note: 'Redo'
}

Hi again,

Are you 100% sure the lineItemId is valid for this order and that it has a refundable quantity greater than or equal to 1 ?

Yes. This is the response we’re getting from the suggestedRefund endpoint, indicating that the line item can be refunded.

{
  "id": "gid://shopify/Order/5852728787109",
  "suggestedRefund": {
    "maximumRefundableSet": { "presentmentMoney": { "amount": "524.43" } },
    "refundLineItems": [
      {
        "id": null,
        "quantity": 1,
        "lineItem": {
          "id": "gid://shopify/LineItem/14210881487013",
          "discountedTotalSet": { "presentmentMoney": { "amount": "178.0" } },
          "originalTotalSet": { "presentmentMoney": { "amount": "178.0" } }
        }
      }
    ],
    "suggestedTransactions": [
      {
        "amountSet": {
          "shopMoney": { "amount": "96.45" },
          "presentmentMoney": { "amount": "96.45" }
        },
        "parentTransaction": {
          "id": "gid://shopify/OrderTransaction/7046407585957"
        },
        "gateway": "shopify_payments",
        "kind": "SUGGESTED_REFUND",
        "maximumRefundableSet": { "presentmentMoney": { "amount": "524.43" } }
      }
    ]
  }
}

It also allows me to refund that item in the Shopify admin UI.

What does this error mean? return_line_items[0].quantity must be greater than 0 Why is it mentioning return_line_items when that field exists nowhere in the mutation?

@Liam-Shopify any insight here? Is there a better place I can reach out to get an answer?

I believe that while your input specifies refundLineItems , Shopify internally maps this to return_line_items when processing the refund request. This mapping is not exposed in the mutation schema but is part of Shopify’s backend logic.

If you query the refundablequantity for the line items on this order - what are you seeing returned?

Hmm makes sense.

And I queried the refundable quantity for that line item and it is 1:

{
  "data": {
    "order": {
      "id": "gid://shopify/Order/5852728787109",
      "lineItems": {
        "nodes": [
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881454245"
          },
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881487013"
          },
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881519781"
          },
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881552549"
          },
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881585317"
          },
          {
            "refundableQuantity": 1,
            "id": "gid://shopify/LineItem/14210881618085"
          }
        ]
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 12,
      "actualQueryCost": 6,
      "throttleStatus": {
        "maximumAvailable": 20000.0,
        "currentlyAvailable": 19994,
        "restoreRate": 1000.0
      }
    }
  }
}

Hi again Devin,

I’ve checked internally and there’s no other reports of this happening with other devs, and it does seem like line item quantity should qualify to allow a refund - I think you’ll need to reach out to support directly who’ll be able to view the logs of your store and see exactly why this is being blocked.

Great, where can I do this?

In your partner dashboard, there’s a support tab, which will lead to a page with a link for “partner support” where there’s an option for “API Support”.