Skip to content

Commit 4a240d5

Browse files
committed
Update new section
1 parent 03fa200 commit 4a240d5

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

src/content/docs/fundamentals/api/how-to/make-api-calls.mdx

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,37 +198,33 @@ curl.exe --request PATCH `
198198

199199
## Environment variables
200200

201-
You can define environment variables for values that repeat between curl commands, such as the zone or account ID. The lifetime of an environment variable can be the current shell session, all future sessions of the current user, or even all future sessions of all users on the machine you are defining them.
201+
You can define environment variables for values that repeat between commands, such as the zone or account ID. The lifetime of an environment variable can be the current shell session, all future sessions of the current user, or even all future sessions of all users on the machine you are defining them.
202202

203203
You can also use environment variables for keeping authentication credentials (API token, API key, and email) for reuse in different commands. However, make sure you define these values in the smallest possible scope (either the current shell session only or all new sessions for the current user).
204204

205-
The procedure for setting environment variables depends on your platform and shell.
205+
The procedure for setting and referencing environment variables depends on your platform and shell.
206206

207-
<Tabs> <TabItem label="Linux and macOS">
207+
### Define an environment variable
208208

209-
To define two environment variables for the current shell session, run the following commands:
209+
<Tabs syncKey="LinuxPowershellCmd"> <TabItem label="Linux and macOS">
210+
211+
To define a `ZONE_ID` environment variable for the current shell session, run the following command:
210212

211213
```sh
212214
export ZONE_ID='f2ea6707005a4da1af1b431202e96ac5'
213-
export CLOUDFLARE_API_TOKEN='<API_TOKEN>'
214215
```
215216

216-
When referencing the variable in curl commands, add a `$` prefix to the variable name (for example, `$ZONE_ID`). Make sure that the full string referencing the variable is either unquoted or enclosed in double quotes (`""`).
217-
218-
To define an environment variable for all new shell sessions for the current user, add the command above at the end of your shell configuration file (for example, `~/.bashrc` for the `bash` shell and `~/.zshrc` for the `zsh` shell).
217+
To define the variable for all new shell sessions for the current user, add the command above at the end of your shell configuration file (for example, `~/.bashrc` for the `bash` shell and `~/.zshrc` for the `zsh` shell).
219218

220219
</TabItem> <TabItem label="PowerShell">
221220

222-
To define two environment variables named `ZONE_ID` and `CLOUDFLARE_API_TOKEN` for the current PowerShell session, run the following commands:
221+
To define a `ZONE_ID` environment variable for the current PowerShell session, run the following command:
223222

224223
```powershell
225224
$Env:ZONE_ID='f2ea6707005a4da1af1b431202e96ac5'
226-
$Env:CLOUDFLARE_API_TOKEN='<API_TOKEN>'
227225
```
228226

229-
When referencing the variable in curl commands, add an `$Env:` prefix to the variable name (for example, `$Env:ZONE_ID`). Make sure that the full string referencing the variable is either unquoted or enclosed in double quotes (`""`).
230-
231-
To define an environment variable for all new PowerShell sessions of the current user, set the variable in your PowerShell profile. You can get the path to your PowerShell profile by running `echo $PROFILE`.
227+
To define the environment variable for all new PowerShell sessions of the current user, set the variable in your PowerShell profile. You can get the path to your PowerShell profile by running `echo $PROFILE`.
232228

233229
Alternatively, set the variable for all new PowerShell sessions of the current user using the `SetEnvironmentVariable()` method of the `System.Environment` class. For example:
234230

@@ -240,21 +236,53 @@ Running this command will not affect the current session. You will need to close
240236

241237
</TabItem> <TabItem label="Windows Command Prompt">
242238

243-
To define a two environment variables for the current Command Prompt session, run the following commands:
239+
To define a `ZONE_ID` environment variable for the current Command Prompt session, run the following command:
244240

245-
```txt
246-
C:\>set ZONE_ID=f2ea6707005a4da1af1b431202e96ac5
247-
C:\>set CLOUDFLARE_API_TOKEN=<API_TOKEN>
241+
```txt frame="terminal"
242+
set ZONE_ID=f2ea6707005a4da1af1b431202e96ac5
248243
```
249244

250-
When referencing a variable in curl commands, enclose the variable name in `%` characters (for example, `%ZONE_ID%`).
251-
252245
To define an environment variable for all future Command Prompt sessions of the current user, run the following command:
253246

254-
```txt
255-
C:\>setx ZONE_ID f2ea6707005a4da1af1b431202e96ac5
247+
```txt frame="terminal"
248+
setx ZONE_ID f2ea6707005a4da1af1b431202e96ac5
256249
```
257250

258251
Running this command will not affect the current window. You will need to either run the `set` command or close and start a new Command Prompt window.
259252

260253
</TabItem> </Tabs>
254+
255+
### Reference an environment variable
256+
257+
<Tabs syncKey="LinuxPowershellCmd"> <TabItem label="Linux and macOS">
258+
259+
When referencing an environment variable in a command, add a `$` prefix to the variable name (for example, `$ZONE_ID`). Make sure that the full string referencing the variable is either unquoted (if it does not contain spaces) or enclosed in double quotes (`""`).
260+
261+
For example:
262+
263+
```sh
264+
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
265+
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
266+
```
267+
268+
</TabItem> <TabItem label="PowerShell">
269+
270+
When referencing an environment variable in a command, add an `$Env:` prefix to the variable name (for example, `$Env:ZONE_ID`). Make sure that the full string referencing the variable is either unquoted or enclosed in double quotes (`""`).
271+
272+
For example:
273+
274+
```powershell
275+
Invoke-RestMethod -URI "https://api.cloudflare.com/client/v4/zones/$Env:ZONE_ID" -Method 'GET' -Headers @{'Authorization'="Bearer $Env:CLOUDFLARE_API_TOKEN"}
276+
```
277+
278+
</TabItem> <TabItem label="Windows Command Prompt">
279+
280+
When referencing an environment variable in a command, enclose the variable name in `%` characters (for example, `%ZONE_ID%`).
281+
282+
For example:
283+
284+
```txt frame="terminal"
285+
curl "https://api.cloudflare.com/client/v4/zones/%ZONE_ID%" --header "Authorization: Bearer %CLOUDFLARE_API_TOKEN%"
286+
```
287+
288+
</TabItem> </Tabs>

0 commit comments

Comments
 (0)