|
2
|
"admin": "import { CodeTabs, CodeTab, H1 } from \"docs-ui\"\nimport { Feedback } from \"@/components/Feedback\"\nimport SectionContainer from \"@/components/Section/Container\"\nimport DividedMarkdownLayout from \"@/layouts/DividedMarkdown\"\nimport { \n DividedMarkdownContent,\n DividedMarkdownCode\n} from \"@/layouts/DividedMarkdown/Sections\"\nimport Section from \"@/components/Section\"\nimport ViewAsMarkdown from \"@/components/ViewAsMarkdown\"\n\nimport ClientLibraries from \"./client-libraries.mdx\"\n\n<Section checkActiveOnScroll>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n<H1 className={\"scroll-m-[184px] lg:scroll-m-[264px] !mb-0\"} id=\"introduction\">Medusa V2 Admin API Reference</H1>\n\n<ViewAsMarkdown path=\"/admin\" className=\"mb-1\" />\n\nThis API reference includes Medusa v2's Admin APIs, which are REST APIs exposed by the Medusa application. They are used to perform admin functionalities or create an admin dashboard to access and manipulate your commerce store's data.\n\nAll API Routes are prefixed with `/admin`. So, during development, the API Routes will be available under the path `http://localhost:9000/admin`. For production, replace `http://localhost:9000` with your Medusa application URL.\n\n<Feedback\n extraData={{\n section: \"introduction\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<ClientLibraries />\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Authentication\n\nThere are three ways to send authenticated requests to the Medusa server: Using a JWT token in a bearer authorization header, using an admin user's API token, or using a cookie session ID.\n\n### 1. Bearer Authorization with JWT Tokens\n\nUse a JWT token in a request's bearer authorization header to send authenticated requests. Authentication state is managed by the client, which is ideal for Jamstack applications and mobile applications.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Obtain the JWT Token\n\nTo obtain a JWT token, send a request to the [authentication route](https://docs.medusajs.com/api/admin/auth/authenticate-user) passing it the user's email and password in the request body.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Obtain JWT token\"\ntoken = await sdk.auth.login(\"user\", \"emailpass\", {\n email,\n password\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Obtain JWT token\"\ncurl -X POST '{backend_url}/auth/user/emailpass' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{\n \"email\": \"user@example.com\",\n \"password\": \"supersecret\"\n}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf authenticated successfully, an object is returned in the response with the property `token` being the JWT token.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```json title=\"Example response\"\n{\n \"token\": \"123...\"\n}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Use the JWT Token\n\nTo use the JWT token, pass it in the authorization bearer header.\n\nIf you're using the JS SDK, the `login` method automatically sets the token for you and passes it to subsequent requests. You can also set the token manually using the `client.setToken` method.\n\n<Note>\n\nMake sure you've set the `auth.type` configuration of the JS SDK to `jwt` to use the JWT token. Learn more in the [JS SDK configurations](!resources!/js-sdk#js-sdk-configurations).\n\n</Note>\n\n<Note title=\"Migrating from v1?\" type=\"warning\">\n\nThe `x-medusa-access-token` header is no longer used in Medusa v2. Pass the JWT token in the `Authorization: Bearer` header instead, as explained here.\n\n</Note>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Use JWT token\"\nAuthorization: Bearer {jwt_token}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### 2. API Token\n\nUse a user's secret API Token to send authenticated requests.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Create an API Token for a User\n\nCreate the API key token either from the [Medusa Admin](!user-guide!/settings/developer/secret-api-keys) or using the [Create API Key API Route](https://docs.medusajs.com/api/admin/api-keys/create-api-key).\n\n<Note>\n\nYou must be an authenticated user to create an API token.\n\n</Note>\n\nAn `api_key` object is returned in the response. You need its `token` property.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Create API token\"\nconst { api_key } = await sdk.admin.apiKey.create({\n title: \"My Token\",\n type: \"secret\"\n})\n\nconsole.log(api_key.token)\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Create API token\"\ncurl -X POST 'localhost:9000/admin/api-keys' \\\n-H 'Content-Type: application/json' \\\n-H 'Authorization: Bearer {jwt_token}' \\\n--data '{\n \"title\": \"my token\",\n \"type\": \"secret\"\n}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Use the API Token\n\nYou pass the API Key token in the Authorization Basic header. For example:\n\n<Note>\n\nPrevious versions of Medusa required passing the API key token as base64. This is still supported for backwards compatibility, but you can pass the API token without encoding it as well.\n\n</Note>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"app-type\">\n\n <CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js\nimport Medusa from \"@medusajs/js-sdk\"\n\nexport const sdk = new Medusa({\n // other options...\n apiKey: \"{api_key_token}\",\n})\n```\n\n </CodeTab>\n <CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Use API token\"\ncurl '{backend_url}/admin/products' \\\n-H 'Authorization: Basic {api_key_token}'\n```\n\n </CodeTab>\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### 3. Cookie Session ID\n\nWhen you authenticate a user and create a cookie session ID for them, the cookie session ID is passed automatically when sending the request from the browser, or with tools like Postman.\n\n### How to Obtain the Cookie Session\n\nTo obtain a cookie session ID, you must have a [JWT token for bearer authentication](#1-bearer-authorization-with-jwt-tokens).\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nThen, if you're using the JS SDK, make sure the `auth.type` configuration is set to `session`, as explained in the [JS SDK configurations](!resources!/js-sdk#js-sdk-configurations) guide. The `auth.login` method will handle setting the session cookie and passing it in subsequent requests.\n\nIf you're not using the JS SDK, send a request to the [session authentication API route](https://docs.medusajs.com/api/admin/auth/set-authentication-session). To view the cookie session ID, pass the `-v` option to the `curl` command.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Obtain cookie session\"\ncurl -v -X POST '{backend_url}/auth/session' \\\n--header 'Authorization: Bearer {jwt_token}'\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you send the `cURL` request, the headers will be logged in the terminal as well as the response. You\nshould find in the headers a Cookie header.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Logged cookie session\"\nSet-Cookie: connect.sid=s%3A2Bu8B...;\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Use the Cookie Session ID in cURL\n\nIf you're using the JS SDK, it will pass the cookie session with every request automatically after you use the `auth.login` method.\n\nIf you're not using the JS SDK, copy the value after `connect.sid` (without the `;` at the end) and pass\nit as a cookie in subsequent requests.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Use cookie session\"\ncurl '{backend_url}/admin/products' \\\n-H 'Cookie: connect.sid={sid}'\n```\n\nWhere `{sid}` is the value of `connect.sid` that you copied.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you're sending requests using JavaScript's Fetch API, you must pass the `credentials` option \nwith the value `include` to all the requests you're sending.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```js title=\"Include credentials in fetch\"\nfetch(`<BACKEND_URL>/admin/products`, {\n credentials: \"include\",\n})\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<Feedback\n extraData={{\n section: \"authentication-cookie\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## HTTP Compression\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you've enabled HTTP Compression in your Medusa configurations, and you \nwant to disable it for some requests, you can pass the `x-no-compression`\nheader in your requests.\n\nIf you're using the JS SDK, every method accepts a `headers` parameter as the last parameter. You can pass in it custom headers, including the `x-no-compression` header.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Disable HTTP compression\"\nsdk.store.product.list({\n limit,\n offset,\n}, {\n \"x-no-compression\": \"false\",\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Disable HTTP compression\"\nx-no-compression: false\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<Feedback\n extraData={{\n section: \"http-compression\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Manage Metadata\n\nMany data models in Medusa, such as products and carts, have a `metadata` field that allows you to store custom information in key-value pairs.\n\nWhen setting or updating the `metadata` field using the relevant API routes, Medusa will merge the new metadata with the existing metadata.\n\n<Note>\n\nThe instructions in this section apply to any [JSON property in a data model](!docs!/learn/fundamentals/data-models/json-properties).\n\n</Note>\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Accepted Values in Metadata\n\nThe `metadata` is an object of key-value pairs, where the keys are strings and the values can be one of the following types:\n\n- String\n - An empty string deletes the property from the metadata.\n- Number\n- Boolean\n- Date\n- Object\n- Arrays of any of the above types\n\nThe `metadata` is not validated, so you can store any custom data in it.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```ts title=\"Metadata Example\"\n{\n \"metadata\": {\n \"category\": \"electronics\",\n \"views\": 1500,\n \"is_featured\": true,\n \"tags\": [\"new\", \"sale\"],\n \"details\": {\n \"warranty\": \"2 years\",\n \"origin\": \"USA\"\n }\n }\n}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Add or Update New Property in Metadata\n\nTo add or update a property in the `metadata`, pass the property in the request body as a key-value pair. This won't affect existing properties in the metadata.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Add new metadata property\"\nsdk.admin.product.update(\"prod_123\", {\n metadata: {\n new_property: \"value\"\n }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"prod_123\",\n \"metadata\": {\n \"new_property\": \"value\",\n \"old_property\": \"value\"\n }\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Update Nested Objects in Metadata\n\nWhen updating a nested object in the `metadata`, you must pass the entire object in the request body.\n\nMedusa doesn't merge nested objects, so if you pass a partial object, the existing properties in the nested object will be removed.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Update nested object in metadata\"\nsdk.admin.product.update(\"prod_123\", {\n metadata: {\n nested_object: {\n property1: \"value1\",\n property2: \"value2\"\n }\n }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"prod_123\",\n \"metadata\": {\n \"nested_object\": {\n \"property1\": \"value1\",\n \"property2\": \"value2\"\n }\n }\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Remove Property from Metadata\n\nTo remove a property from the `metadata`, pass the property in the request body with an empty string value. This will remove the property from the `metadata` without affecting other properties.\n\n<Feedback\n extraData={{\n section: \"metadata\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Remove metadata property\"\nsdk.admin.product.update(\"prod_123\", {\n metadata: {\n property_to_remove: \"\"\n }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"prod_123\",\n \"metadata\": {\n \"other_property\": \"value\"\n }\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Select Fields and Relations\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nMany API Routes accept a `fields` query that allows you to select which fields and relations should be returned in a record.\nFields and relations are separated by a comma `,`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select fields\"\nsdk.admin.product.list({\n fields: \"title,handle\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select fields\"\ncurl 'localhost:9000/admin/products?fields=title,handle' \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns only the `title` and `handle` fields of a product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n### Allowed and Disallowed Fields\n\nAn API route can restrict the fields and relations that you can retrieve:\n\n- Allowed fields and relations are the only ones you can retrieve in the API route. If an API route has no allowed fields, you can retrieve any field or relation.\n- Disallowed fields and relations are the ones you can never retrieve in the API route, even if you pass them in the `fields` query parameter.\n\nIf an API route has any of these restrictions, they're listed in its documentation in the Allowed and Disallowed collapsibles.\n\nTo learn more about these restrictions and how to override them, refer to the [Allowed Fields](!docs!/learn/fundamentals/api-routes/allowed-fields) and [Disallowed Fields](!docs!/learn/fundamentals/api-routes/disallowed-fields) documentation.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Fields Operator\n\nBy default, only the selected fields and relations are returned in the response.\n\nBefore every field or relation, you can pass one of the following operators to change the default behavior:\n\n- `+`: Add the field to the fields returned by default. For example, `+title` returns the `title` field along with the fields returned by default.\n- `-`: Remove the field from the fields returned by default. For example, `-handle` removes the `handle` field from the fields returned by default.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relations\"\nsdk.admin.product.list({\n fields: \"+title,-handle\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relations\"\ncurl 'localhost:9000/admin/products?fields=+title,-handle'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the products, each of them having their `title` field, but without the `handle` field.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Select Relations\n\nTo select a relation, pass to `fields` the relation name prefixed by `*`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relations\"\nsdk.admin.product.list({\n fields: \"*variants\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relations\"\ncurl 'localhost:9000/admin/products?fields=*variants' \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n</CodeTabs>\n\nThis returns the variants of each product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nTo select multiple relations, pass each of the relations with the `*` prefix, separated by a comma.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relation's fields\"\nsdk.admin.product.list({\n fields: \"*variants,*options\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relation's fields\"\ncurl 'localhost:9000/admin/products?fields=*variants,*options'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants and options of each product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Select Fields in a Relation\n\nThe `*` prefix selects all fields of the relation's data model.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\nTo select a specific field, pass a `.<field>` suffix instead of the `*` prefix. For example, `variants.title`.\n\nTo specify multiple fields, pass each of the fields with the `<relation>.<field>` format, separated by a comma. You can do the same for multiple relations.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relation's fields\"\nsdk.admin.product.list({\n fields: \"variants.title,variants.sku,options.title\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relation's fields\"\ncurl 'localhost:9000/admin/products?fields=variants.title,variants.sku,options.title' \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis 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.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Select Nested Relations\n\nA relation can have relations of its own. To select a nested relation, chain the relation names with a dot (`.`), prefixing the deepest relation with `*` to select all its fields. For example, `*variants.prices`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nPrefixing a relation with `*` only selects that relation's own fields, not its nested relations. So, to retrieve a nested relation, you must reference it explicitly through its parent, as shown in the example.\n\nYou can chain more relations to select deeper levels, such as `*items.variant.product`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select nested relations\"\nsdk.admin.product.list({\n fields: \"*variants.prices\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select nested relations\"\ncurl 'localhost:9000/admin/products?fields=*variants.prices' \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants of each product, each with its `prices` relation populated.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n### Select Custom Linked Data Models\n\nMost of the API routes that accept a `fields` query parameter allow you to specify custom linked data models. For example, if you linked a `Brand` to a `Product`, you can pass `brand` in the `fields` query parameter to retrieve the brand of each product.\n\nHowever, some API routes restrict the fields and relations you can retrieve. To learn about those API routes and how to override the allowed fields and relations, refer to the [Retrieve Custom Linked Data Models from Medusa's API routes](!docs!/learn/fundamentals/api-routes/retrieve-custom-links) documentation.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"select-fields\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Query Parameter Types\n\n\nThis section covers how to pass some common data types as query parameters.\n\nThis is useful if you're sending requests to the API Routes using cURL or Postman.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Strings\n\n\nYou can pass a string value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"String filter\"\nsdk.admin.product.list({\n title: \"Shirt\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"String filter\"\ncurl \"http://localhost:9000/admin/products?title=Shirt\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf the string has any characters other than letters and numbers, you must\nencode them. For example, if the string has spaces, you can encode the space with `+` or\n`%20`.\n\nWhen using the JS SDK, you can pass the string directly to the query parameter. The JS SDK will encode the string for you.\n\nYou can use tools like [this one](https://www.urlencoder.org/) to learn how\na value can be encoded.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Encoded string filter\"\nsdk.admin.product.list({\n title: \"Blue Shirt\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Encoded string filter\"\ncurl \"http://localhost:9000/admin/products?title=Blue%20Shirt\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Integers\n\nYou can pass an integer value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Integer filter\"\nsdk.admin.product.list({\n offset: 1\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Integer filter\"\ncurl \"http://localhost:9000/admin/products?offset=1\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Boolean\n\n\nYou can pass a boolean value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Boolean filter\"\nsdk.admin.product.list({\n is_giftcard: true\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Boolean filter\"\ncurl \"http://localhost:9000/admin/products?is_giftcard=true\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Date and DateTime\n\n\nYou can pass a date value in the form `<parameter_name>=<value>`. The date\nmust be in the format `YYYY-MM-DD`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Date filter\"\nsdk.admin.product.list({\n created_at: { $lt: \"2023-02-17\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Date filter\"\ncurl -g \"http://localhost:9000/admin/products?created_at[$lt]=2023-02-17\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nYou can also pass the time using the format `YYYY-MM-DDTHH:MM:SSZ`. Please\nnote that the `T` and `Z` here are fixed.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Date and time filter\"\nsdk.admin.product.list({\n created_at: { $lt: \"2023-02-17T07:22:30Z\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Date and time filter\"\ncurl -g \"http://localhost:9000/admin/products?created_at[$lt]=2023-02-17T07:22:30Z\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Array\n\nArray filters can be passed either as:\n\n- `<parameter_name>[]=<value1>,<value2>`, separating the values by a comma.\n- `<parameter_name>[]=<value1>&<parameter_name>[]=<value2>`, passing each value as a separate query parameter. You can also specify the index of each\nparameter in the brackets `<parameter_name>[0]=<value>`.\n\nWhen using the JS SDK, you can pass the array directly to the query parameter. The JS SDK will handle the rest.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"array-filter\">\n <CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Array filter\"\nsdk.admin.product.list({\n sales_channel_id: [\"sc_123\", \"sc_456\"]\n})\n```\n\n </CodeTab>\n <CodeTab label=\"Comma-separated\" value=\"comma-separated\">\n\n```bash\ncurl -g \"http://localhost:9000/admin/products?sales_channel_id[]=sc_123,sc_456\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n </CodeTab>\n <CodeTab label=\"Separate parameters\" value=\"separate-query-parameters\">\n\n```bash\ncurl -g \"http://localhost:9000/admin/products?sales_channel_id[]=sc_123&sales_channel_id[]=sc_456\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n </CodeTab>\n</CodeTabs>\n\nNote that the `-g` parameter passed to `curl` disables errors being thrown\nfor using the brackets. Read more\n[here](https://curl.se/docs/manpage.html#-g).\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Object\n\n\nObject parameters must be passed as separate query parameters in the form\n`<parameter_name>[<key>]=<value>`.\n\nWhen using the JS SDK, you can pass the object directly to the query parameter. The JS SDK will handle the rest.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Object filter\"\nsdk.admin.product.list({\n created_at: { $lt: \"2023-02-17\", $gt: \"2022-09-17\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Object filter\"\ncurl -g \"http://localhost:9000/admin/products?created_at[$lt]=2023-02-17&created_at[$gt]=2022-09-17\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"query-parameters\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Pagination\n\n### Query Parameters\n\n\nIn listing API Routes, such as list customers or list products, you can control the pagination using the query parameters `limit` and `offset`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n`limit` is used to specify the maximum number of items to be returned in the response. `offset` is used to specify how many items to skip before returning the resulting records.\n\n\nUse the `offset` query parameter to change between pages. For example, if the limit is `50`, at page `1` the offset should be `0`; at page `2` the offset should be `50`, and so on.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Pagination query parameters\"\nsdk.admin.product.list({\n limit: 5,\n offset: 0\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Pagination query parameters\"\ncurl \"http://localhost:9000/admin/products?limit=5&offset=0\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Response Fields\n\n\nIn the response of listing API Routes, aside from the records retrieved,\nthere are three pagination-related fields returned:\n\n\n- `limit`: the maximum number of items that can be returned in the response.\n- `offset`: the number of items that were skipped before the records in the result.\n- `count`: the total number of available items of this data model. It can be used to determine how many pages are there.\n\n\nFor example, if the `count` is `100` and the `limit` is `50`, divide the\n`count` by the `limit` to get the number of pages: `100/50 = 2 pages`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Sort Order\n\n\nThe `order` field (available on API Routes that support pagination) allows you to\nsort the retrieved items by a field of that item.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Ascending sort by a field\"\nsdk.admin.product.list({\n order: \"created_at\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Ascending sort by a field\"\ncurl \"http://localhost:9000/admin/products?order=created_at\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis sorts the products by their `created_at` field in the ascending order.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nBy default, the sort direction is ascending. To change it to\ndescending, pass a dash (`-`) before the field name.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Descending sort by a field\"\nsdk.admin.product.list({\n order: \"-created_at\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Descending sort by a field\"\ncurl \"http://localhost:9000/admin/products?order=-created_at\" \\\n-H 'Authorization: Bearer {jwt_token}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis sorts the products by their `created_at` field in the descending order.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"pagination\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Workflows\n\nWhile browsing this reference, you'll find some API routes mention what workflow is used in them.\n\nIf you click on the workflow, you'll view a reference of that workflow, including its hooks.\n\nThis is useful if you want to extend an API route and pass additional data or perform custom actions.\n\nRefer to [this guide](!docs!/learn/customization/extend-features/extend-create-product) to find an example of extending an API route.\n\n<Feedback\n extraData={{\n section: \"workflows\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n</Section>", |
|
3
|
"store": "import SectionContainer from \"@/components/Section/Container\"\nimport DividedMarkdownLayout from \"@/layouts/DividedMarkdown\"\nimport { \n DividedMarkdownContent,\n DividedMarkdownCode\n} from \"@/layouts/DividedMarkdown/Sections\"\nimport Section from \"@/components/Section\"\nimport { CodeTabs, CodeTab, H1, Prerequisites } from \"docs-ui\"\nimport { Feedback } from \"@/components/Feedback\"\nimport ViewAsMarkdown from \"@/components/ViewAsMarkdown\"\n\nimport ClientLibraries from \"./client-libraries.mdx\"\n\n<Section checkActiveOnScroll>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n<H1 className={\"scroll-m-[184px] lg:scroll-m-[264px] !mb-0\"} id=\"introduction\">Medusa V2 Store API Reference</H1>\n\n<ViewAsMarkdown path=\"/store\" className=\"mb-1\" />\n\nThis API reference includes Medusa v2's Store APIs, which are REST APIs exposed by the Medusa application. They are used to create a storefront for your commerce store, such as a webshop or a commerce mobile app.\n\nAll API Routes are prefixed with `/store`. So, during development, the API Routes will be available under the path `http://localhost:9000/store`. For production, replace `http://localhost:9000` with your Medusa application URL.\n\n<Feedback\n extraData={{\n section: \"introduction\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<ClientLibraries />\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Authentication\n\nThere are two ways to send authenticated requests to the Medusa application: Using a JWT token or using a Cookie Session ID.\n\n### 1. Bearer Authorization with JWT Tokens\n\nUse a JWT token in a request's bearer authorization header to send authenticated requests. Authentication state is managed by the client, which is ideal for Jamstack applications and mobile applications.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Obtain the JWT Token\n\nTo obtain a JWT token, send a request to the [authentication route](https://docs.medusajs.com/api/store/auth/authenticate-customer) passing it the customer's email and password in the request body.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Obtain JWT token\"\ntoken = await sdk.auth.login(\"customer\", \"emailpass\", {\n email,\n password\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Obtain JWT token\"\ncurl -X POST '{backend_url}/auth/customer/emailpass' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{\n \"email\": \"user@example.com\",\n \"password\": \"supersecret\"\n}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf authenticated successfully, an object is returned in the response with the property `token` being the JWT token.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```json title=\"Example response\"\n{\n \"token\": \"123...\"\n}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Use the JWT Token\n\nTo use the JWT token, pass it in the authorization bearer header.\n\nIf you're using the JS SDK, the `login` method automatically sets the token for you and passes it to subsequent requests. You can also set the token manually using the `client.setToken` method.\n\n<Note>\n\nMake sure you've set the `auth.type` configuration of the JS SDK to `jwt` to use the JWT token. Learn more in the [JS SDK configurations](!resources!/js-sdk#js-sdk-configurations).\n\n</Note>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Use JWT token\"\nAuthorization: Bearer {jwt_token}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### 2. Cookie Session ID\n\nWhen you authenticate a customer and create a cookie session ID for them, the cookie session ID is passed automatically when sending the request from the browser, or with tools like Postman.\n\n### How to Obtain the Cookie Session\n\nTo obtain a cookie session ID, you must have a [JWT token for bearer authentication](#1-bearer-authorization-with-jwt-tokens).\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nThen, if you're using the JS SDK, make sure the `auth.type` configuration is set to `session`, as explained in the [JS SDK configurations](!resources!/js-sdk#js-sdk-configurations) guide. The `auth.login` method will handle setting the session cookie and passing it in subsequent requests.\n\nIf you're not using the JS SDK, send a request to the [session authentication API route](https://docs.medusajs.com/api/store/auth/set-authentication-session). To view the cookie session ID, pass the `-v` option to the `curl` command.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Obtain cookie session\"\ncurl -v -X POST '{backend_url}/auth/session' \\\n--header 'Authorization: Bearer {jwt_token}'\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you send the `cURL` request, the headers will be logged in the terminal as well as the response. You\nshould find in the headers a Cookie header.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Logged cookie session\"\nSet-Cookie: connect.sid=s%3A2Bu8B...;\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### How to Use the Cookie Session ID in cURL\n\nIf you're using the JS SDK, it will pass the cookie session with every request automatically after you use the `auth.login` method.\n\nIf you're not using the JS SDK, copy the value after `connect.sid` (without the `;` at the end) and pass\nit as a cookie in subsequent requests.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```bash title=\"Use cookie session\"\ncurl '{backend_url}/store/products' \\\n-H 'Cookie: connect.sid={sid}'\n```\n\nWhere `{sid}` is the value of `connect.sid` that you copied.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n#### Including Credentials in the Fetch API\n\nIf you're sending requests using JavaScript's Fetch API, you must pass the `credentials` option \nwith the value `include` to all the requests you're sending.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```js title=\"Include credentials in fetch\"\nfetch(`<BACKEND_URL>/store/products`, {\n credentials: \"include\",\n})\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<Feedback\n extraData={{\n section: \"authentication-cookie\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Publishable API Key\n\nYou must pass a publishable API key in the header of your requests to the store API routes.\n\nPublishable API Keys sets the scope of your request to one or more sales channels. This ensures you only\nretrieve products available in the publishable API key's sales channels, retrieve correct inventory details,\nand associate placed orders with the specified sales channel.\n\n### How to Create a Publishable API Key\n\nCreate a publishable API key either using the [admin REST APIs](https://docs.medusajs.com/api/admin/api-keys/create-api-key), or using the [Medusa Admin](!user-guide!/settings/developer/publishable-api-keys#create-publishable-api-key).\n\n### How to Use a Publishable API Key\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you're using the JS SDK, set the publishable API key in the JS SDK's configurations.\n\nIf you're not using the JS SDK, pass the publishable API key in the header `x-publishable-api-key` in all your requests to the store APIs.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Use publishable API key\"\nimport Medusa from \"@medusajs/js-sdk\"\n\nexport const sdk = new Medusa({\n // other configurations...\n publishableKey: \"{your_publishable_api_key}\",\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Use publishable API key\"\ncurl 'http://localhost:9000/store/products' \\\n-H 'x-publishable-api-key: {your_publishable_api_key}'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nWhere `{your_publishable_api_key}` is the token of the publishable API key. When using the JS SDK, set the value as an environment variable.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"publishable-api-key\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## HTTP Compression\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf you've enabled HTTP Compression in your Medusa configurations, and you \nwant to disable it for some requests, you can pass the `x-no-compression`\nheader in your requests.\n\nIf you're using the JS SDK, every method accepts a `headers` parameter as the last parameter. You can pass in it custom headers, including the `x-no-compression` header.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Disable HTTP compression\"\nsdk.store.product.list({\n limit,\n offset,\n}, {\n \"x-no-compression\": \"false\",\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Disable HTTP compression\"\nx-no-compression: false\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"http-compression\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Manage Metadata\n\nMany data models in Medusa, such as products and carts, have a `metadata` field that allows you to store custom information in key-value pairs.\n\nWhen setting or updating the `metadata` field using the relevant API routes, Medusa will merge the new metadata with the existing metadata.\n\n<Note>\n\nThe instructions in this section apply to any [JSON property in a data model](!docs!/learn/fundamentals/data-models/json-properties).\n\n</Note>\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Accepted Values in Metadata\n\nThe `metadata` is an object of key-value pairs, where the keys are strings and the values can be one of the following types:\n\n- String\n - An empty string deletes the property from the metadata.\n- Number\n- Boolean\n- Date\n- Object\n- Arrays of any of the above types\n\nThe `metadata` is not validated, so you can store any custom data in it.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n```ts title=\"Metadata Example\"\n{\n \"metadata\": {\n \"category\": \"electronics\",\n \"views\": 1500,\n \"is_featured\": true,\n \"tags\": [\"new\", \"sale\"],\n \"details\": {\n \"warranty\": \"2 years\",\n \"origin\": \"USA\"\n }\n }\n}\n```\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Add or Update New Property in Metadata\n\nTo add or update a property in the `metadata`, pass the property in the request body as a key-value pair. This won't affect existing properties in the metadata.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Add new metadata property\"\nsdk.store.cart.updateLineItem(\n \"cart_123\",\n \"li_123\",\n {\n metadata: {\n new_property: \"value\"\n }\n }\n)\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"cart_123\",\n \"items\": [\n {\n \"id\": \"li_123\",\n \"metadata\": {\n \"new_property\": \"value\",\n \"old_property\": \"value\"\n }\n }\n ]\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Update Nested Objects in Metadata\n\nWhen updating a nested object in the `metadata`, you must pass the entire object in the request body.\n\nMedusa doesn't merge nested objects, so if you pass a partial object, the existing properties in the nested object will be removed.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Update nested object in metadata\"\nsdk.store.cart.updateLineItem(\n \"cart_123\",\n \"li_123\",\n {\n metadata: {\n nested_object: {\n property1: \"value1\",\n property2: \"value2\"\n }\n }\n }\n)\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"cart_123\",\n \"items\": [\n {\n \"id\": \"li_123\",\n \"metadata\": {\n \"nested_object\": {\n \"property1\": \"value1\",\n \"property2\": \"value2\"\n }\n }\n }\n ]\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Remove Property from Metadata\n\nTo remove a property from the `metadata`, pass the property in the request body with an empty string value. This will remove the property from the `metadata` without affecting other properties.\n\n<Feedback\n extraData={{\n section: \"metadata\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-with-result\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Remove metadata property\"\nsdk.store.cart.updateLineItem(\n \"cart_123\",\n \"li_123\",\n {\n metadata: {\n property_to_remove: \"\"\n }\n }\n)\n```\n\n</CodeTab>\n\n<CodeTab label=\"Result\" value=\"result\">\n\n```json title=\"Result\"\n{\n \"id\": \"cart_123\",\n \"items\": [\n {\n \"id\": \"li_123\",\n \"metadata\": {\n \"other_property\": \"value\"\n }\n }\n ]\n}\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Select Fields and Relations\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nMany API Routes accept a `fields` query that allows you to select which fields and relations should be returned in a record.\nFields and relations are separated by a comma `,`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select fields\"\nsdk.store.product.list({\n fields: \"title,handle\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select fields\"\ncurl 'localhost:9000/store/products?fields=title,handle'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns only the `title` and `handle` fields of a product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n### Allowed and Disallowed Fields\n\nAn API route can restrict the fields and relations that you can retrieve:\n\n- Allowed fields and relations are the only ones you can retrieve in the API route. Every Store API route has an allowed list, so you can only retrieve the fields and relations that it includes. A field is permitted only if its full path is in the list, so selecting a relation doesn't grant access to the fields nested under it.\n- Disallowed fields and relations are the ones you can never retrieve in the API route, even if you pass them in the `fields` query parameter.\n\nIf an API route has any of these restrictions, they're listed in this reference under the Allowed and Disallowed collapsibles. Medusa removes restricted fields from the response silently, so the request still succeeds with a `200` status code.\n\nTo learn more about these restrictions and how to override them, refer to the [Allowed Fields](!docs!/learn/fundamentals/api-routes/allowed-fields) and [Disallowed Fields](!docs!/learn/fundamentals/api-routes/disallowed-fields) documentation.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Fields Operator\n\nBy default, only the selected fields and relations are returned in the response.\n\nBefore every field or relation, you can pass one of the following operators to change the default behavior:\n\n- `+`: Add the field to the fields returned by default. For example, `+title` returns the `title` field along with the fields returned by default.\n- `-`: Remove the field from the fields returned by default. For example, `-handle` removes the `handle` field from the fields returned by default.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relations\"\nsdk.store.product.list({\n fields: \"+title,-handle\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relations\"\ncurl 'localhost:9000/store/products?fields=+title,-handle'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the products, each of them having their `title` field, but without the `handle` field.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Select Relations\n\nTo select a relation, pass to `fields` the relation name prefixed by `*`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relations\"\nsdk.store.product.list({\n fields: \"*variants\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relations\"\ncurl 'localhost:9000/store/products?fields=*variants'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants of each product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nTo select multiple relations, pass each of the relations with the `*` prefix, separated by a comma.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relation's fields\"\nsdk.store.product.list({\n fields: \"*variants,*options\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relation's fields\"\ncurl 'localhost:9000/store/products?fields=*variants,*options'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants and options of each product.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Select Fields in a Relation\n\nThe `*` prefix selects all fields of the relation's data model.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nTo select a specific field, pass a `.<field>` suffix instead of the `*` prefix. For example, `variants.manage_inventory`.\n\nTo specify multiple fields, pass each of the fields with the `<relation>.<field>` format, separated by a comma. You can do the same for multiple relations.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select relation's fields\"\nsdk.store.product.list({\n fields: \"variants.manage_inventory,variants.allow_backorder,options.values\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select relation's fields\"\ncurl 'localhost:9000/store/products?fields=variants.manage_inventory,variants.allow_backorder,options.values'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants and options of each product, but the variants only have their `id`, `manage_inventory`, and `allow_backorder` fields, and the options only have their `id` and `values` fields. The `id` is always included.\n\n<Note>\n\nEach Store API route accepts only the field paths listed in its allowed fields. So, the nested paths you pass must appear in that list. Learn more in the [Allowed and Disallowed Fields](#allowed-and-disallowed-fields) section.\n\n</Note>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Select Nested Relations\n\nA relation can have relations of its own. To select a nested relation, chain the relation names with a dot (`.`), prefixing the deepest relation with `*` to select all its fields. For example, `*variants.prices`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nPrefixing a relation with `*` only selects that relation's own fields, not its nested relations. So, to retrieve a nested relation, you must reference it explicitly through its parent, as shown in the example.\n\nYou can chain more relations to select deeper levels, such as `*items.variant.product`. On Store API routes, the route's allowed fields must include the full nested path, such as `variants.prices`. Referencing the parent relation alone doesn't grant access to what's nested under it.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Select nested relations\"\nsdk.store.product.list({\n fields: \"*variants.prices\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Select nested relations\"\ncurl 'localhost:9000/store/products?fields=*variants.prices'\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis returns the variants of each product, each with its `prices` relation populated.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n### Select Custom Linked Data Models\n\nYou can retrieve custom linked data models in the `fields` query parameter. For example, if you linked a `Brand` to a `Product`, you can pass `brand` in the `fields` query parameter to retrieve the brand of each product.\n\nSince every Store API route restricts the fields and relations you can retrieve, you must first add the custom linked data model to the route's allowed list. To learn how to override the allowed fields and relations, refer to the [Retrieve Custom Linked Data Models from Medusa's API routes](!docs!/learn/fundamentals/api-routes/retrieve-custom-links) documentation.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"select-fields\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Query Parameter Types\n\n\nThis section covers how to pass some common data types as query parameters.\n\nThis is useful if you're sending requests to the API Routes using cURL or Postman.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Strings\n\n\nYou can pass a string value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"String filter\"\nsdk.store.product.list({\n title: \"Shirt\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"String filter\"\ncurl \"http://localhost:9000/store/products?title=Shirt\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nIf the string has any characters other than letters and numbers, you must\nencode them. For example, if the string has spaces, you can encode the space with `+` or\n`%20`.\n\nWhen using the JS SDK, you can pass the string directly to the query parameter. The JS SDK will encode the string for you.\n\nYou can use tools like [this one](https://www.urlencoder.org/) to learn how\na value can be encoded.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Encoded string filter\"\nsdk.store.product.list({\n title: \"Blue Shirt\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Encoded string filter\"\ncurl \"http://localhost:9000/store/products?title=Blue%20Shirt\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Integers\n\nYou can pass an integer value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Integer filter\"\nsdk.store.product.list({\n offset: 1\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Integer filter\"\ncurl \"http://localhost:9000/store/products?offset=1\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Boolean\n\n\nYou can pass a boolean value in the form of `<parameter_name>=<value>`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Boolean filter\"\nsdk.store.product.list({\n is_giftcard: true\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Boolean filter\"\ncurl \"http://localhost:9000/store/products?is_giftcard=true\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Date and DateTime\n\n\nYou can pass a date value in the form `<parameter_name>=<value>`. The date\nmust be in the format `YYYY-MM-DD`.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Date filter\"\nsdk.store.product.list({\n created_at: { $lt: \"2023-02-17\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Date filter\"\ncurl -g \"http://localhost:9000/store/products?created_at[$lt]=2023-02-17\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nYou can also pass the time using the format `YYYY-MM-DDTHH:MM:SSZ`. Please\nnote that the `T` and `Z` here are fixed.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Date and time filter\"\nsdk.store.product.list({\n created_at: { $lt: \"2023-02-17T07:22:30Z\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Date and time filter\"\ncurl -g \"http://localhost:9000/store/products?created_at[$lt]=2023-02-17T07:22:30Z\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Array\n\nArray filters can be passed either as:\n\n- `<parameter_name>[]=<value1>,<value2>`, separating the values by a comma.\n- `<parameter_name>[]=<value1>&<parameter_name>[]=<value2>`, passing each value as a separate query parameter. You can also specify the index of each\nparameter in the brackets `<parameter_name>[0]=<value>`.\n\nWhen using the JS SDK, you can pass the array directly to the query parameter. The JS SDK will handle the rest.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"array-filter\">\n <CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Array filter\"\nsdk.store.product.list({\n sales_channel_id: [\"sc_123\", \"sc_456\"]\n})\n```\n\n </CodeTab>\n <CodeTab label=\"Comma-separated\" value=\"comma-separated\">\n\n```bash\ncurl -g \"http://localhost:9000/store/products?sales_channel_id[]=sc_123,sc_456\"\n```\n\n </CodeTab>\n <CodeTab label=\"Separate parameters\" value=\"separate-query-parameters\">\n\n```bash\ncurl -g \"http://localhost:9000/store/products?sales_channel_id[]=sc_123&sales_channel_id[]=sc_456\"\n```\n\n </CodeTab>\n</CodeTabs>\n\nNote that the `-g` parameter passed to `curl` disables errors being thrown\nfor using the brackets. Read more\n[here](https://curl.se/docs/manpage.html#-g).\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Object\n\n\nObject parameters must be passed as separate query parameters in the form\n`<parameter_name>[<key>]=<value>`.\n\nWhen using the JS SDK, you can pass the object directly to the query parameter. The JS SDK will handle the rest.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Object filter\"\nsdk.store.product.list({\n created_at: { $lt: \"2023-02-17\", $gt: \"2022-09-17\" }\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Object filter\"\ncurl -g \"http://localhost:9000/store/products?created_at[$lt]=2023-02-17&created_at[$gt]=2022-09-17\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"query-parameters\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Pagination\n\n\n### Query Parameters\n\n\nIn listing API Routes, such as list products, you can control the pagination using the query parameters `limit` and `offset`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n`limit` is used to specify the maximum number of items to be returned in the response. `offset` is used to specify how many items to skip before returning the resulting records.\n\n\nUse the `offset` query parameter to change between pages. For example, if the limit is `50`, at page `1` the offset should be `0`; at page `2` the offset should be `50`, and so on.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Pagination query parameters\"\nsdk.store.product.list({\n limit: 5,\n offset: 0\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Pagination query parameters\"\ncurl \"http://localhost:9000/store/products?limit=5&offset=0\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\n### Response Fields\n\n\nIn the response of listing API Routes, aside from the records retrieved,\nthere are three pagination-related fields returned:\n\n\n- `limit`: the maximum number of items that can be returned in the response.\n- `offset`: the number of items that were skipped before the records in the result.\n- `count`: the total number of available items of this data model. It can be used to determine how many pages are there.\n\n\nFor example, if the `count` is `100` and the `limit` is `50`, divide the\n`count` by the `limit` to get the number of pages: `100/50 = 2 pages`.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing codeContentClassName=\"mt-3\">\n\n<DividedMarkdownContent>\n\n### Sort Order\n\n\nThe `order` field (available on API Routes that support pagination) allows you to\nsort the retrieved items by a field of that item.\n\nOn Store API routes, the field you sort by must also be in the route's allowed list. If it isn't, the request fails with a `400` error, such as `Order field X is not valid`. This differs from the `fields` query parameter, which removes disallowed fields silently instead of returning an error.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Ascending sort by a field\"\nsdk.store.product.list({\n order: \"created_at\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Ascending sort by a field\"\ncurl \"http://localhost:9000/store/products?order=created_at\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis sorts the products by their `created_at` field in the ascending order.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nBy default, the sort direction is ascending. To change it to\ndescending, pass a dash (`-`) before the field name.\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-examples\">\n\n<CodeTab label=\"JS SDK\" value=\"js-sdk\">\n\n```js title=\"Descending sort by a field\"\nsdk.store.product.list({\n order: \"-created_at\"\n})\n```\n\n</CodeTab>\n\n<CodeTab label=\"cURL\" value=\"curl\">\n\n```bash title=\"Descending sort by a field\"\ncurl \"http://localhost:9000/store/products?order=-created_at\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\nThis sorts the products by their `created_at` field in the descending order.\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"pagination\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Workflows\n\nWhile browsing this reference, you'll find some API routes mention what workflow is used in them.\n\nIf you click on the workflow, you'll view a reference of that workflow, including its hooks.\n\nThis is useful if you want to extend an API route and pass additional data or perform custom actions.\n\nRefer to [this guide](!docs!/learn/customization/extend-features/extend-create-product) to find an example of extending an API route.\n\n<Feedback\n extraData={{\n section: \"workflows\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n<SectionContainer noTopPadding={true}>\n\n<DividedMarkdownLayout>\n\n<DividedMarkdownContent>\n\n## Localization\n\n<Prerequisites\n items={[\n {\n text: \"Translation Module Configured\",\n link: \"!resources!/commerce-modules/translation#configure-translation-module\",\n }\n ]}\n/>\n\nMedusa's Store APIs support localization of core and custom data models. Refer to the [Translation Module](!resources!/commerce-modules/translation) guide to learn about supported core data models, and how to [configure translations for custom data models](!resources!/commerce-modules/translation/custom-data-models).\n\nBy default, the Store APIs returns the original data without localization.\n\n</DividedMarkdownContent>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout addYSpacing>\n\n<DividedMarkdownContent>\n\nYou can set the locale of a request using one of the following methods:\n\n- Use the JS SDK's `setLocale` method. The JS SDK will automatically include the locale in the `x-medusa-locale` header of subsequent requests.\n- Pass the `locale` query parameter to the relevant API route. By default, all `/store` API routes support the `locale` query parameter.\n- Set the `x-medusa-locale` header in the API request to the relevant API route. By default, all `/store` API routes support the `x-medusa-locale` header.\n\nLocales are in the [IETF BCP 47](https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1) format, such as `en-US` for American English, or `fr-FR` for French.\n\nThe returned data will be in the specified locale if a translation exists. Otherwise, it will fall back to the original data.\n\nLearn more in the [Storefront Localization guide](!resources!/storefront-development/localization).\n\n</DividedMarkdownContent>\n\n<DividedMarkdownCode>\n\n<CodeTabs group=\"request-localization-examples\">\n\n<CodeTab label=\"Using JS SDK\" value=\"js-sdk\">\n\n```js\nsdk.setLocale(\"fr-FR\")\n// products content will be in French\nconst { products } = await sdk.store.product.list()\n```\n\n</CodeTab>\n\n<CodeTab label=\"Using Query Parameter\" value=\"query-param\">\n\n```bash\ncurl \"http://localhost:9000/store/products?locale=fr-FR\" \\\n-H 'x-publishable-api-key: {your_publishable_api_key}'\n```\n\n</CodeTab>\n<CodeTab label=\"Using Header\" value=\"header\">\n\n```bash\ncurl \"http://localhost:9000/store/products\" \\\n-H 'x-publishable-api-key: {your_publishable_api_key}' \\\n-H \"x-medusa-locale: fr-FR\"\n```\n\n</CodeTab>\n\n</CodeTabs>\n\n\n</DividedMarkdownCode>\n\n</DividedMarkdownLayout>\n\n<DividedMarkdownLayout>\n\n<Feedback\n extraData={{\n section: \"localization\"\n }}\n question=\"Was this section helpful?\"\n/>\n\n</DividedMarkdownLayout>\n\n</SectionContainer>\n\n</Section>" |