Skip to content

Commit

Permalink
docs: fix and improve details on sending authenticated requests with …
Browse files Browse the repository at this point in the history
…API token
  • Loading branch information
shahednasser committed Dec 26, 2024
1 parent ee50e67 commit 773aa64
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
39 changes: 34 additions & 5 deletions www/apps/api-reference/markdown/admin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Authorization: Bearer {jwt_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>

Expand All @@ -145,7 +145,7 @@ Use a user's API Token to send authenticated requests.

#### 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>

Expand Down Expand Up @@ -180,16 +180,45 @@ curl -X POST 'localhost:9000/admin/api-keys' \
#### 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>

<DividedMarkdownCode>

```bash title="Use API token"
Authorization: Basic {api_key_token}
<CodeTabs group="app-type">
<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>

</DividedMarkdownLayout>
Expand Down
2 changes: 1 addition & 1 deletion www/apps/api-reference/markdown/client-libraries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

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

Expand Down

0 comments on commit 773aa64

Please sign in to comment.