Sending a package back
A return is a shipment that runs the other way: origin is your customer, destination is your warehouse. Envia creates that shipment the same way it creates any other — and then you record it against the order it came from, so the store and the buyer both see what is happening.
You need this if you sell online and accept returns.
Two calls, not oneEnvia does not generate the return label as part of registering the return. You create the label first with the Shipping API, then register it. Both steps are yours to make, in this order.
The two steps
1. Create the return label
An ordinary POST /ship/generate with the addresses swapped: origin is the customer, destination is the address you want the goods back at.
curl --request POST \
--url https://api-test.envia.com/ship/generate/ \
--header "Authorization: Bearer $ENVIA_TOKEN" \
--header 'Content-Type: application/json' \
--data '{
"origin": {
"name": "Laura Mendoza",
"street": "Av. Insurgentes Sur",
"number": "1602",
"city": "Ciudad de Mexico",
"state": "CMX",
"country": "MX",
"postalCode": "03940",
"phone": "5555555555",
"email": "[email protected]"
},
"destination": {
"name": "Bodega Central",
"street": "Calle Industria",
"number": "45",
"city": "Guadalajara",
"state": "JAL",
"country": "MX",
"postalCode": "44100",
"phone": "3333333333",
"email": "[email protected]"
},
"packages": [
{
"content": "Return - 2 items",
"amount": 1,
"type": "box",
"weight": 1.4,
"weightUnit": "KG",
"lengthUnit": "CM",
"declaredValue": 1200,
"dimensions": { "length": 30, "width": 20, "height": 12 }
}
],
"shipment": { "carrier": "fedex", "service": "ground", "type": 1 },
"settings": { "printFormat": "PDF", "printSize": "STOCK_4X6", "comments": "Return" }
}'Keep four values from the response: shipment_id, trackingNumber, trackUrl and label.
2. Register it against the order
POST /orders/{shop_id}/{order_id}/return ties that shipment to the order and the products coming back.
curl --request POST \
--url https://queries.test.envia.com/orders/33488/9087654/return \
--header "Authorization: Bearer $ENVIA_TOKEN" \
--header 'Content-Type: application/json' \
--data '{
"package_info": {
"order_address_id": 441233,
"name": "Return - 2 items",
"content": "1 running shoe, 1 t-shirt",
"weight": 1.4,
"weight_unit": "KG",
"length": 30,
"width": 20,
"height": 12,
"length_unit": "CM",
"declared_value": 1200,
"package_type_id": 1
},
"products": [
{
"id": 7781201,
"quantity": 1,
"reason": "Wrong size",
"product_identifier": "gid://shopify/LineItem/13277665",
"order_package_id": 553311
}
],
"shipment": {
"shipment_id": 182941,
"tracking_number": "794657894999",
"url": "https://envia.com/track/794657894999",
"document": "https://s3.amazonaws.com/envia/uploads/fedex/label-182941.pdf"
}
}'{ "success": true }What that second call actually does
- Creates a return package on the order, flagged as a return, with the dimensions you sent.
- Copies the selected products onto it, each carrying the
reasonthe customer gave. The reason is stored and forwarded — it is how you later answer why are people returning this product. - Attaches the shipment from step 1.
- Calls the connected store to open the return there and hand it the tracking number and the label, so the buyer sees it in their order history.
The store leg is synchronous. If the store rejects the return, the whole call fails with 422 and the message comes from the store, not from Envia.
Set the return address once
POST /config/return/address/{config_address_id} marks one of your saved addresses as the one returns come back to. There can be only one per company: turning it on for an address clears it on every other.
It toggles, it does not setCalling it on an address that is already the return address clears the flag and leaves your company with none. Read the current state first, and only call it when it needs to change.
Things that will bite you
| Not idempotent | Calling POST .../return twice registers two returns. Keep your own record of which orders have been returned. |
| Products must be on the order | Every products[].id is an order_products.id from this order, and quantity may not exceed what was bought. Either mistake is a 400 that names the product. |
order_id is Envia's, not the store's | Use the id from GET /v4/orders, not the order number the buyer sees. |
product_identifier is the store's | It is how the store matches the line item on its side. Send what the store gave you. |
COD and insurance travel in additional_services | Only cash_on_delivery and insurance are read on a return package; each takes its amount in data.amount. |
What is not covered yet
There is no customer-facing returns portal behind the API: the buyer cannot request a return through an Envia endpoint, and there is no rules engine deciding what is returnable. Those decisions live in your store or your own software today; this API records the outcome and moves the package.
Need Help?Building a returns flow and something isn't behaving as expected?
Our support team is ready to help 🚀Create a support ticket here and we'll guide you through setup and troubleshooting.