Shopify api refund and cancel

Topic summary

A developer is encountering an issue when attempting to cancel and refund Shopify orders via the REST API using Python.

Current Behavior:

  • Order cancellation completes successfully
  • Payment status remains “paid” instead of showing as refunded
  • Using API version 2022-07 with separate cancel and refund endpoints

Implementation Details:

  • Code creates a refund object with parameters including order_id, amount, note, shipping details, and refund_line_items
  • Calls both order.cancel() and refund.save() methods
  • Specifies full refund with “restock_type” set to “no_restock”

Status: The issue remains unresolved with no responses or solutions provided yet. The developer needs guidance on why the refund isn’t processing correctly despite successful order cancellation.

Summarized with AI on November 24. AI used: claude-sonnet-4-5-20250929.

i want to cancel and refund order using python when Im refunding iget this response
POST https://xxxxxxxtest.myshopify.com/xxxx/api/2022-07/orders/xxxxxx/cancel.json
POST https://xxxxxxxtest.myshopify.com/xxxx/api/2022-07/orders/xxxxxx/refunds.json

order is canceling succesful but Payment Status is paid and no refunded: its my code

order = shopify.Order.find(order_id)
order.cancel()
order.save()
refund = shopify.Refund({
“note”: “Refund for cancelled order”,
“order_id”: order.id,
“amount”: order.total_price,
“shipping”: {
“full_refund”: True
},
“refund_line_items”: [
{
“line_item_id”: order.line_items[0].id,
“quantity”: order.line_items[0].quantity,
“location_id”: None,
“restock_type”: “no_restock”
}
]
})
refund.save()