Fetching relationships

How to directly fetch related resources

You can fetch either single related resources or collections by sending GET requests to the "related" link /api/<parent_resource>/:id/<related_resource> (i.e. the parent resource endpoint, specifying the single parent resource ID and the related resource you want to retrieve).

Make sure to use the relationship name and not the resource name (e.g., if you want to retrieve the billing address associated with an order, use billing_address and not just addressessee example)

When fetching a list of related resources results can be sorted (see example) and filtered (see examples).

Examples

The following request fetches the billing address associated with the order identified by the ID "xYZkjABcde":

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/orders/xYZkjABcde/billing_address' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

The following request fetches the order history of a specific customer, i.e. the list of orders associated with the customer identified by the ID "xYZkjABcde":

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/orders' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

Last updated