Skip to content

Commit 428b1c8

Browse files
authored
[Fundamentals] Added info for account and user tokens (#19372)
* Added info for account and user tokens * Edited example URL to be consistent with style guide
1 parent bc92e8a commit 428b1c8

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

src/content/docs/fundamentals/api/how-to/create-via-api.mdx

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66

77
---
88

9-
import { Render } from "~/components"
9+
import { Render, Tabs, TabItem } from "~/components"
1010

1111
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.
1212

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

2525
## Creating API tokens with the API
2626

27-
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.
27+
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.
2828

2929
To create a token:
3030

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

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

133+
<Tabs>
134+
<TabItem label="Account token">
135+
```bash
136+
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/tokens" \
137+
--header "Authorization: Bearer <API_TOKEN>" \
138+
--header "Content-Type: application/json" \
139+
--data '{
140+
"name": "readonly token",
141+
"policies": [
142+
{
143+
"effect": "allow",
144+
"resources": {
145+
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
146+
"com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43": "*"
147+
},
148+
"permission_groups": [
149+
{
150+
"id": "c8fed203ed3043cba015a93ad1616f1f",
151+
"name": "Zone Read"
152+
},
153+
{
154+
"id": "82e64a83756745bbbb1c9c2701bf816b",
155+
"name": "DNS Read"
156+
}
157+
]
158+
}
159+
],
160+
"not_before": "2020-04-01T05:20:00Z",
161+
"expires_on": "2020-04-10T00:00:00Z",
162+
"condition": {
163+
"request.ip": {
164+
"in": [
165+
"199.27.128.0/21",
166+
"2400:cb00::/32"
167+
],
168+
"not_in": [
169+
"199.27.128.1/32"
170+
]
171+
}
172+
}
173+
}'
174+
```
175+
</TabItem>
176+
<TabItem label="User token">
177+
```bash
178+
curl "https://api.cloudflare.com/client/v4/user/tokens" \
179+
--header "Authorization: Bearer <API_TOKEN>" \
180+
--header "Content-Type: application/json" \
181+
--data '{
182+
"name": "readonly token",
183+
"policies": [
184+
{
185+
"effect": "allow",
186+
"resources": {
187+
"com.cloudflare.api.account.zone.eb78d65290b24279ba6f44721b3ea3c4": "*",
188+
"com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43": "*"
189+
},
190+
"permission_groups": [
191+
{
192+
"id": "c8fed203ed3043cba015a93ad1616f1f",
193+
"name": "Zone Read"
194+
},
195+
{
196+
"id": "82e64a83756745bbbb1c9c2701bf816b",
197+
"name": "DNS Read"
198+
}
199+
]
200+
}
201+
],
202+
"not_before": "2020-04-01T05:20:00Z",
203+
"expires_on": "2020-04-10T00:00:00Z",
204+
"condition": {
205+
"request.ip": {
206+
"in": [
207+
"199.27.128.0/21",
208+
"2400:cb00::/32"
209+
],
210+
"not_in": [
211+
"199.27.128.1/32"
212+
]
213+
}
214+
}
215+
}'
216+
```
217+
</TabItem>
218+
</Tabs>
219+
133220
```bash
134221
curl "https://api.cloudflare.com/client/v4/user/tokens" \
135222
--header "Authorization: Bearer <API_TOKEN>" \

0 commit comments

Comments
 (0)