Skip to content
Community forum

Linking an order to a customer after both exist

SolvedSupero SupportSupero team asked

Common question, written up by the Supero team.

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?

Link

1 answer

Accepted answer
Accepted answer

Declare the link in the order schema's references[], then add it with ref-update:

bash
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.

Supero Platform teamSupero team answered
Link

Your answer

Linking an order to a customer after both exist | Supero Community