docs: fix and improve details on sending authenticated requests with API token (#10744)
* docs: fix and improve details on sending authenticated requests with API token * fix security schema
This commit is contained in:
@@ -133,7 +133,7 @@ Authorization: Bearer {jwt_token}
|
|||||||
|
|
||||||
### 2. API Token
|
### 2. API Token
|
||||||
|
|
||||||
Use a user's API Token to send authenticated requests.
|
Use a user's secret API Token to send authenticated requests.
|
||||||
|
|
||||||
</DividedMarkdownContent>
|
</DividedMarkdownContent>
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ Use a user's API Token to send authenticated requests.
|
|||||||
|
|
||||||
#### How to Create an API Token for a User
|
#### How to Create an API Token for a User
|
||||||
|
|
||||||
Use the [Create API Key API Route](#api-keys_postapikeys) to create an API token.
|
Create the API key token either from the Medusa Admin or using the [Create API Key API Route](#api-keys_postapikeys).
|
||||||
|
|
||||||
<Note>
|
<Note>
|
||||||
|
|
||||||
@@ -180,16 +180,45 @@ curl -X POST 'localhost:9000/admin/api-keys' \
|
|||||||
#### How to Use the API Token
|
#### How to Use the API Token
|
||||||
|
|
||||||
|
|
||||||
Use the API token by passing it in a basic authorization header.
|
You pass the API Key token as a base64 token in the authorization header. For example, when sending a request in JavaScript:
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
|
||||||
|
When using the JS SDK, you only need to specify the API key token in the [configurations](!resources!/js-sdk#js-sdk-configurations). The JS SDK will handle passing the token as expected.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
</DividedMarkdownContent>
|
</DividedMarkdownContent>
|
||||||
|
|
||||||
<DividedMarkdownCode>
|
<DividedMarkdownCode>
|
||||||
|
|
||||||
```bash title="Use API token"
|
<CodeTabs group="app-type">
|
||||||
Authorization: Basic {api_key_token}
|
<CodeTab label="Browser / Client" value="client">
|
||||||
|
|
||||||
|
```js
|
||||||
|
fetch(`{backend_url}/admin/products`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${window.btoa(`:${api_key_token}`)}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</CodeTab>
|
||||||
|
<CodeTab label="Node.js / Server" value="server">
|
||||||
|
|
||||||
|
```js
|
||||||
|
fetch(`{backend_url}/admin/products`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${
|
||||||
|
Buffer.from(`:${api_key_token}`).toString("base64")
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeTab>
|
||||||
|
</CodeTabs>
|
||||||
|
|
||||||
</DividedMarkdownCode>
|
</DividedMarkdownCode>
|
||||||
|
|
||||||
</DividedMarkdownLayout>
|
</DividedMarkdownLayout>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ To use Medusa's JS SDK library, install the following packages in your project (
|
|||||||
npm install @medusajs/js-sdk@latest @medusajs/types@latest
|
npm install @medusajs/js-sdk@latest @medusajs/types@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
Learn more about the JS SDK in [this documentation](!resources!/js-sdk).
|
Learn more about the JS SDK and how to configure it in [this documentation](!resources!/js-sdk).
|
||||||
|
|
||||||
### Download Full Reference
|
### Download Full Reference
|
||||||
|
|
||||||
|
|||||||
@@ -69757,10 +69757,9 @@ components:
|
|||||||
type: unknown_error
|
type: unknown_error
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
api_token:
|
api_token:
|
||||||
type: apiKey
|
type: http
|
||||||
x-displayName: API Token
|
x-displayName: API Token
|
||||||
in: header
|
scheme: bearer
|
||||||
name: x-medusa-access-token
|
|
||||||
jwt_token:
|
jwt_token:
|
||||||
type: http
|
type: http
|
||||||
x-displayName: JWT Token
|
x-displayName: JWT Token
|
||||||
|
|||||||
@@ -1028,10 +1028,9 @@ paths:
|
|||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
api_token:
|
api_token:
|
||||||
type: apiKey
|
type: http
|
||||||
x-displayName: API Token
|
x-displayName: API Token
|
||||||
in: header
|
scheme: bearer
|
||||||
name: x-medusa-access-token
|
|
||||||
jwt_token:
|
jwt_token:
|
||||||
type: http
|
type: http
|
||||||
x-displayName: JWT Token
|
x-displayName: JWT Token
|
||||||
|
|||||||
@@ -5031,14 +5031,6 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
title: category_id
|
title: category_id
|
||||||
description: A product category's ID.
|
description: A product category's ID.
|
||||||
- name: currency_code
|
|
||||||
in: query
|
|
||||||
description: The currency code to retrieve prices in.
|
|
||||||
required: false
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
title: currency_code
|
|
||||||
description: The currency code to retrieve prices in.
|
|
||||||
- name: variants
|
- name: variants
|
||||||
in: query
|
in: query
|
||||||
description: Filter the products' variants.
|
description: Filter the products' variants.
|
||||||
@@ -5063,6 +5055,22 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
title: value
|
title: value
|
||||||
description: Filter by a value of the option.
|
description: Filter by a value of the option.
|
||||||
|
- name: country_code
|
||||||
|
in: query
|
||||||
|
description: The product's country code.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
title: country_code
|
||||||
|
description: The product's country code.
|
||||||
|
- name: cart_id
|
||||||
|
in: query
|
||||||
|
description: The product's cart id.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
title: cart_id
|
||||||
|
description: The product's cart id.
|
||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: Shell
|
- lang: Shell
|
||||||
label: cURL
|
label: cURL
|
||||||
|
|||||||
@@ -789,14 +789,6 @@ get:
|
|||||||
type: string
|
type: string
|
||||||
title: category_id
|
title: category_id
|
||||||
description: A product category's ID.
|
description: A product category's ID.
|
||||||
- name: currency_code
|
|
||||||
in: query
|
|
||||||
description: The currency code to retrieve prices in.
|
|
||||||
required: false
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
title: currency_code
|
|
||||||
description: The currency code to retrieve prices in.
|
|
||||||
- name: variants
|
- name: variants
|
||||||
in: query
|
in: query
|
||||||
description: Filter the products' variants.
|
description: Filter the products' variants.
|
||||||
@@ -821,6 +813,22 @@ get:
|
|||||||
type: string
|
type: string
|
||||||
title: value
|
title: value
|
||||||
description: Filter by a value of the option.
|
description: Filter by a value of the option.
|
||||||
|
- name: country_code
|
||||||
|
in: query
|
||||||
|
description: The product's country code.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
title: country_code
|
||||||
|
description: The product's country code.
|
||||||
|
- name: cart_id
|
||||||
|
in: query
|
||||||
|
description: The product's cart id.
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
title: cart_id
|
||||||
|
description: The product's cart id.
|
||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: Shell
|
- lang: Shell
|
||||||
label: cURL
|
label: cURL
|
||||||
|
|||||||
@@ -735,10 +735,9 @@ components:
|
|||||||
type: unknown_error
|
type: unknown_error
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
api_token:
|
api_token:
|
||||||
type: apiKey
|
type: http
|
||||||
x-displayName: API Token
|
x-displayName: API Token
|
||||||
in: header
|
scheme: bearer
|
||||||
name: x-medusa-access-token
|
|
||||||
jwt_token:
|
jwt_token:
|
||||||
type: http
|
type: http
|
||||||
x-displayName: JWT Token
|
x-displayName: JWT Token
|
||||||
|
|||||||
Reference in New Issue
Block a user