Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fundamentals] Added info for account and user tokens #19372

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 89 additions & 2 deletions src/content/docs/fundamentals/api/how-to/create-via-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar:

---

import { Render } from "~/components"
import { Render, Tabs, TabItem } from "~/components"

Generate new API tokens on the fly via the API. Before you can do this, you must create an API token in the Cloudflare dashboard that can create subsequent tokens.

Expand All @@ -24,7 +24,7 @@ Cloudflare also recommends limiting the use of the token via client IP address f

## Creating API tokens with the API

Once you create an API token that can create other tokens, you can now use it in the API. Refer to the [API schema docs](/api/resources/user/subresources/tokens/methods/create/) for more information.
You can create a user owned token or account owned token to use with the API. Refer to the [user owned token](/api/resources/user/subresources/tokens/methods/create/) or the [account owned token](/api/resources/accounts/subresources/tokens/methods/create/) API schema docs for more information.

To create a token:

Expand Down Expand Up @@ -130,6 +130,93 @@ Each parameter in the `in` and `not_in` objects must be in CIDR notation. For ex

Combine the previous information to create a token as in the following example:

<Tabs>
<TabItem label="Account token">
```bash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/tokens" \
dcpena marked this conversation as resolved.
Show resolved Hide resolved
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"name": "readonly token",
"policies": [
{
"effect": "allow",
"resources": {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
"com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43": "*"
},
"permission_groups": [
{
"id": "c8fed203ed3043cba015a93ad1616f1f",
"name": "Zone Read"
},
{
"id": "82e64a83756745bbbb1c9c2701bf816b",
"name": "DNS Read"
}
]
}
],
"not_before": "2020-04-01T05:20:00Z",
"expires_on": "2020-04-10T00:00:00Z",
"condition": {
"request.ip": {
"in": [
"199.27.128.0/21",
"2400:cb00::/32"
],
"not_in": [
"199.27.128.1/32"
]
}
}
}'
```
</TabItem>
<TabItem label="User token">
```bash
curl "https://api.cloudflare.com/client/v4/user/tokens" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"name": "readonly token",
"policies": [
{
"effect": "allow",
"resources": {
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
"com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43": "*"
},
"permission_groups": [
{
"id": "c8fed203ed3043cba015a93ad1616f1f",
"name": "Zone Read"
},
{
"id": "82e64a83756745bbbb1c9c2701bf816b",
"name": "DNS Read"
}
]
}
],
"not_before": "2020-04-01T05:20:00Z",
"expires_on": "2020-04-10T00:00:00Z",
"condition": {
"request.ip": {
"in": [
"199.27.128.0/21",
"2400:cb00::/32"
],
"not_in": [
"199.27.128.1/32"
]
}
}
}'
```
</TabItem>
</Tabs>

```bash
curl "https://api.cloudflare.com/client/v4/user/tokens" \
--header "Authorization: Bearer <API_TOKEN>" \
Expand Down
Loading