0
0
PowerShellscripting~10 mins

REST API calls with Invoke-RestMethod in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a GET request to the URL and store the response.

PowerShell
$response = Invoke-RestMethod -Uri [1]
Drag options to blanks, or click blank then click option'
A"https://api.example.com/data"
BGet-Content
C-Method POST
DInvoke-WebRequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using a cmdlet name instead of a URL string.
Forgetting to put the URL in quotes.
Using the wrong parameter like -Method POST instead of -Uri.
2fill in blank
medium

Complete the code to send a POST request with JSON data to the API.

PowerShell
Invoke-RestMethod -Uri "https://api.example.com/submit" -Method [1] -Body $jsonData -ContentType "application/json"
Drag options to blanks, or click blank then click option'
APOST
BDELETE
CPUT
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST when sending data.
Forgetting to set the ContentType to application/json.
3fill in blank
hard

Fix the error in the code to correctly add a custom header to the REST API request.

PowerShell
$headers = @{ "Authorization" = [1] }
Invoke-RestMethod -Uri "https://api.example.com/data" -Headers $headers
Drag options to blanks, or click blank then click option'
ABearer token123
B"Bearer token123"
Ctoken123
D'Bearer token123'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the header value causing errors.
Using single quotes which also work but the task expects double quotes.
4fill in blank
hard

Fill both blanks to create a REST API call that sends JSON data with a custom header.

PowerShell
$headers = @{ "Content-Type" = [1] }
Invoke-RestMethod -Uri "https://api.example.com/update" -Method [2] -Headers $headers -Body $jsonPayload
Drag options to blanks, or click blank then click option'
A"application/json"
BPOST
CGET
D"text/plain"
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method when sending data.
Setting Content-Type to text/plain instead of application/json.
5fill in blank
hard

Fill all three blanks to parse JSON response and extract a property value.

PowerShell
$response = Invoke-RestMethod -Uri "https://api.example.com/info"
$value = $response.[1]
if ($value -eq [2]) {
    Write-Output [3]
}
Drag options to blanks, or click blank then click option'
Astatus
B"success"
C"Operation completed"
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names.
Forgetting quotes around string values.
Not outputting a string message.