Both records are already created. What's the call to link the order to its customer, and how do I list a customer's orders afterwards?
Linking an order to a customer after both exist
Common question, written up by the Supero team.
1 answer
Declare the link in the order schema's references[], then add it with ref-update:
curl -X PUT https://api.supero.dev/api/v1/crud/acme/ref-update \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"type": "order", "uuid": "<order uuid>", "ref-type": "customer", "ref-uuid": "<customer uuid>", "operation": "ADD"}'operation is ADD, UPDATE or DELETE. For many edits in one call, PUT /api/v1/crud/{domain}/ref-update-multi takes an updates array of the same entries. In Python it's org.crud.set_ref("order", order_uuid, "customer", customer_uuid).
From the order, GET /api/v1/crud/acme/order/{uuid}/refs/customer returns the link. From the customer, GET /api/v1/crud/acme/customer/{uuid}/back-refs?back_ref_type=order lists the orders pointing at it, and POST /list-bulk with "type": "order" and back_ref_id does the same with paging.
Adding a reference needs create or update permission on the order and read on the customer. Changing or removing one needs update on both.
Your answer
Know the answer? Sign in to post it. It takes an email address and a 6-digit code.
Sign in to answer