A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello there hope you all are well,
Maybe someone has encountered this problem before, I am still battling with it.
I have an order with two transactions, I want to be able to refund them with the api, the only snag is, associating the line_items with the relevant transactions.
The line_items are just in 1 indiscriminate array.
I am attempting to at the moment do some fancy looping in order to add up the price of the line items until they match the relevant transaction amount paid.
Is there maybe an easier way?
Unfortunately performing GET requests on the transactions endpoint does not return any line_items.
GET requests on the order itself also provides (in my eyes) no obvious way to match line_items with their transaction.
Cheers,
Matthias
P.S. as a feature request having the API return the line_items associated with a transaction could smooth out this proccess
Solved! Go to the solution
This is an accepted solution.
Ok, so I was actually making my own problems, because:
When refunding an order through the API:
-> the line_items can just be put all into 1 array
-> they do NOT need to be broken up into different arrays based on which transaction they belonged to (I don't know why I thought that)
so here is an example JSON sent in the REST admin API to the orders/refunds endpoint (because the shopify documentation does not provide one).
{
"refund": {
"notify": "true",
"note": "",
"shipping": {
"full_refund": "false"
},
"refund_line_items": [
{
"price": 191.94,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
},
{
"price": 155.94,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
},
{
"price": 21,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
}
],
"transactions": [
{
"parent_id": xxx,
"currency": "EUR",
"amount": "347.88",
"kind": "refund",
"gateway": "bogus"
},
{
"parent_id": xxx,
"currency": "EUR",
"amount": "21.00",
"kind": "refund",
"gateway": "bogus"
}
]
}
}
So, this was the answer to my problem, I hope it was helpful to some :))
Cheers,
Matthias7
This is an accepted solution.
Ok, so I was actually making my own problems, because:
When refunding an order through the API:
-> the line_items can just be put all into 1 array
-> they do NOT need to be broken up into different arrays based on which transaction they belonged to (I don't know why I thought that)
so here is an example JSON sent in the REST admin API to the orders/refunds endpoint (because the shopify documentation does not provide one).
{
"refund": {
"notify": "true",
"note": "",
"shipping": {
"full_refund": "false"
},
"refund_line_items": [
{
"price": 191.94,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
},
{
"price": 155.94,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
},
{
"price": 21,
"line_item_id": xxx,
"quantity": 1,
"restock_type": "no_restock",
"location_id": xxx
}
],
"transactions": [
{
"parent_id": xxx,
"currency": "EUR",
"amount": "347.88",
"kind": "refund",
"gateway": "bogus"
},
{
"parent_id": xxx,
"currency": "EUR",
"amount": "21.00",
"kind": "refund",
"gateway": "bogus"
}
]
}
}
So, this was the answer to my problem, I hope it was helpful to some :))
Cheers,
Matthias7