diff --git a/www/apps/api-reference/markdown/admin.mdx b/www/apps/api-reference/markdown/admin.mdx index e26980bc4b..a5fadf2a86 100644 --- a/www/apps/api-reference/markdown/admin.mdx +++ b/www/apps/api-reference/markdown/admin.mdx @@ -760,10 +760,38 @@ By default, only the selected fields and relations are returned in the response. Before every field or relation, you can pass one of the following operators to change the default behavior: - `+`: Add the field to the fields returned by default. For example, `+title` returns the `title` field along with the fields returned by default. -- `-`: Remove the field from the fields returned by default. For example, `-title` removes the `title` field from the fields returned by default. +- `-`: Remove the field from the fields returned by default. For example, `-handle` removes the `handle` field from the fields returned by default. + + + + + + +```js title="Select relations" +sdk.admin.product.list({ + fields: "+title,-handle" +}) +``` + + + + + +```bash title="Select relations" +curl 'localhost:9000/admin/products?fields=+title,-handle' +``` + + + + + +This returns the products, each of them having their `title` field, but without the `handle` field. + + + @@ -810,6 +838,44 @@ This returns the variants of each product. +To select multiple relations, pass each of the relations with the `*` prefix, separated by a comma. + + + + + + + + + +```js title="Select relation's fields" +sdk.admin.product.list({ + fields: "*variants,*options" +}) +``` + + + + + +```bash title="Select relation's fields" +curl 'localhost:9000/admin/products?fields=*variants,*options' +``` + + + + + +This returns the variants and options of each product. + + + + + + + + + ### Select Fields in a Relation The `*` prefix selects all fields of the relation's data model. @@ -824,7 +890,7 @@ The `*` prefix selects all fields of the relation's data model. To select a specific field, pass a `.` suffix instead of the `*` prefix. For example, `variants.title`. -To specify multiple fields, pass each of the fields with the `.` format, separated by a comma. +To specify multiple fields, pass each of the fields with the `.` format, separated by a comma. You can do the same for multiple relations. @@ -836,7 +902,7 @@ To specify multiple fields, pass each of the fields with the `. ```js title="Select relation's fields" sdk.admin.product.list({ - fields: "variants.title,variants.sku" + fields: "variants.title,variants.sku,options.title" }) ``` @@ -845,7 +911,7 @@ sdk.admin.product.list({ ```bash title="Select relation's fields" -curl 'localhost:9000/admin/products?fields=variants.title,variants.sku' \ +curl 'localhost:9000/admin/products?fields=variants.title,variants.sku,options.title' \ -H 'Authorization: Bearer {jwt_token}' ``` @@ -853,7 +919,7 @@ curl 'localhost:9000/admin/products?fields=variants.title,variants.sku' \ -This returns the variants of each product, but the variants only have their `id`, `title`, and `sku` fields. The `id` is always included. +This returns the variants and options of each product, but the variants only have their `id`, `title`, and `sku` fields, and the options only have their `id` and `title` fields. The `id` is always included. diff --git a/www/apps/api-reference/markdown/store.mdx b/www/apps/api-reference/markdown/store.mdx index 401a52f0b8..59e5e6daef 100644 --- a/www/apps/api-reference/markdown/store.mdx +++ b/www/apps/api-reference/markdown/store.mdx @@ -744,10 +744,38 @@ By default, only the selected fields and relations are returned in the response. Before every field or relation, you can pass one of the following operators to change the default behavior: - `+`: Add the field to the fields returned by default. For example, `+title` returns the `title` field along with the fields returned by default. -- `-`: Remove the field from the fields returned by default. For example, `-title` removes the `title` field from the fields returned by default. +- `-`: Remove the field from the fields returned by default. For example, `-handle` removes the `handle` field from the fields returned by default. + + + + + + +```js title="Select relations" +sdk.store.product.list({ + fields: "+title,-handle" +}) +``` + + + + + +```bash title="Select relations" +curl 'localhost:9000/store/products?fields=+title,-handle' +``` + + + + + +This returns the products, each of them having their `title` field, but without the `handle` field. + + + @@ -794,6 +822,44 @@ This returns the variants of each product. +To select multiple relations, pass each of the relations with the `*` prefix, separated by a comma. + + + + + + + + + +```js title="Select relation's fields" +sdk.store.product.list({ + fields: "*variants,*options" +}) +``` + + + + + +```bash title="Select relation's fields" +curl 'localhost:9000/store/products?fields=*variants,*options' +``` + + + + + +This returns the variants and options of each product. + + + + + + + + + ### Select Fields in a Relation The `*` prefix selects all fields of the relation's data model. @@ -808,7 +874,7 @@ The `*` prefix selects all fields of the relation's data model. To select a specific field, pass a `.` suffix instead of the `*` prefix. For example, `variants.title`. -To specify multiple fields, pass each of the fields with the `.` format, separated by a comma. +To specify multiple fields, pass each of the fields with the `.` format, separated by a comma. You can do the same for multiple relations. @@ -820,7 +886,7 @@ To specify multiple fields, pass each of the fields with the `. ```js title="Select relation's fields" sdk.store.product.list({ - fields: "variants.title,variants.sku" + fields: "variants.title,variants.sku,options.title" }) ``` @@ -829,14 +895,14 @@ sdk.store.product.list({ ```bash title="Select relation's fields" -curl 'localhost:9000/store/products?fields=variants.title,variants.sku' +curl 'localhost:9000/store/products?fields=variants.title,variants.sku,options.title' ``` -This returns the variants of each product, but the variants only have their `id`, `title`, and `sku` fields. The `id` is always included. +This returns the variants and options of each product, but the variants only have their `id`, `title`, and `sku` fields, and the options only have their `id` and `title` fields. The `id` is always included.