What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Whole order refunds via the graphql api

Solved

Whole order refunds via the graphql api

benny14
Tourist
4 1 1

Hi, 

I'm attempting to perform a complete refund on an order using graphql.

Query:

mutation refundCreate($input: RefundInput!) {
refundCreate(input: $input) {
order {
id
}
refund {
id
}
userErrors {
field
message
}
}
}
 
Variables:
{
"input":{
"orderId": "gid://shopify/Order/4080952148***",
"note": "Order refunded",
"notify": true,
"refundLineItems": {
"lineItemId": "gid://shopify/LineItem/10464944947***",
"quantity": 1
},
"shipping": {
"fullRefund": true
}
}
}
 
The response appears successful (I include all the line items and shipping etc.) but the order in the store's Shopify back office does not change to 'refunded' what step am I missing?
 
Thanks
Accepted Solution (1)

benny14
Tourist
4 1 1

This is an accepted solution.

Managed to resolve this myself in the end. 

I get the order data I need for refunding using this...

Query:

query ($id: ID!) {
node(id:$id) {
id
...on Order {
name
email
id
lineItems(first: 100) {
edges {
node {
id
refundableQuantity
}
}
}
transactions(first: 5) {
id
kind
gateway
parentTransaction {
id
}
amountSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
 
Variables:
{
"id": "gid://shopify/Order/40461712*****"
}
 
 
Then run the refund...
Query:
mutation refundCreate($input: RefundInput!) {
refundCreate(input: $input) {
order {
id
}
refund {
id
}
userErrors {
field
message
}
}
}
 
Variables:
{
"input":{
"orderId": "gid://shopify/Order/40461712****",
"note": "Agechecked.com - Unable to verify age",
"notify": true,
"refundLineItems": {
"lineItemId": "gid://shopify/LineItem/103967428****",
"quantity": 1
},
"shipping": {
"fullRefund": true
},
"transactions": {
"amount": "6.99",
"gateway": "bogus",
"kind": "REFUND",
"parentId": "gid://shopify/OrderTransaction/48704215****",
"orderId": "gid://shopify/Order/40461712****"
}
}
}
 
Hope it helps someone else.

View solution in original post

Reply 1 (1)

benny14
Tourist
4 1 1

This is an accepted solution.

Managed to resolve this myself in the end. 

I get the order data I need for refunding using this...

Query:

query ($id: ID!) {
node(id:$id) {
id
...on Order {
name
email
id
lineItems(first: 100) {
edges {
node {
id
refundableQuantity
}
}
}
transactions(first: 5) {
id
kind
gateway
parentTransaction {
id
}
amountSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
 
Variables:
{
"id": "gid://shopify/Order/40461712*****"
}
 
 
Then run the refund...
Query:
mutation refundCreate($input: RefundInput!) {
refundCreate(input: $input) {
order {
id
}
refund {
id
}
userErrors {
field
message
}
}
}
 
Variables:
{
"input":{
"orderId": "gid://shopify/Order/40461712****",
"note": "Agechecked.com - Unable to verify age",
"notify": true,
"refundLineItems": {
"lineItemId": "gid://shopify/LineItem/103967428****",
"quantity": 1
},
"shipping": {
"fullRefund": true
},
"transactions": {
"amount": "6.99",
"gateway": "bogus",
"kind": "REFUND",
"parentId": "gid://shopify/OrderTransaction/48704215****",
"orderId": "gid://shopify/Order/40461712****"
}
}
}
 
Hope it helps someone else.