Sending a gift
One of the ways you can use the Commerce API is to send a gift. When you send a gift, you can create an order without an address, and you’ll get a gift link that you can send to the recipient. The recipient can then enter their own address and accept the gift. To send a gift, you’ll want to create what we call an order batch. Since Goody lets you send gifts to multiple recipients at once, the “container” for all gifts is an order batch. When you create an order batch, you provide a list of recipients. Each recipient in the gift batch will have an order created for them. If you’re sending a single gift at a time, you’ll also be creating an order batch – just with one recipient. Think of it as sending an email: whether you’re sending an email to one recipient or multiple, you’re still composing the same email. The endpoint to create a gift batch is POST /v1/order_batches:
These fields are optional, but recommended:
Create order batch response
The response looks like:- If you send an order batch with 10 or fewer recipients, orders are processed right away, and you’ll see that that
send_statusiscompleteand you’ll receive the list of orders back in theorders_previewobject. - If you send an order batch with more than 10 recipients, creating orders happens asynchronously in the background, and you’ll see that
send_statusispending. You can hit the/order_batches/:idendpoint to check thesend_statusforcomplete, or listen for theorder_batch.completedwebhook.- The
orders_previewendpoint only contains the first 10 orders. If you have more orders, you can paginate through all the orders using the/order_batches/:id/ordersendpoint.
- The
- If you schedule an order batch for the future using the
scheduled_send_onparameter, thesend_statuswill bepending, andorders_previewwill be empty, until the scheduled send time, at which point the orders are created. Similarly to above, you can listen for theorder_batch.completedwebhook.
send_status field to determine if your order batch is being asynchronously processed or is scheduled for the future (send_status == pending) or orders are ready (send_status == complete).
The orders_preview field
The most important thing in the response is the order object. The orders_preview field displays the first 10 orders in your order batch. To determine the number of orders in the order batch, you can use the orders_count field.
/order_batches/:id/orders endpoint to paginate through the rest of your orders.
In the order object, there are a few fields to point out:
individual_gift_link— This is the individual gift link for that recipient, which when opened goes directly to their gift. You can send this in an email or somewhere else so they can access their gift.status— This status is for the individual order itself. The list of order statuses can be viewed on the order lifecycle guide. You can set up webhooks to get notified on changes to the status.amounts— Contains the costs for this order, in cents.