I used but getting bad request below is the screenshot:
Could you please help me in this
The base url should be api.Meraki.com, and not your shard url.
I have tried but same error below is the script and output:
script:
$apiKey = "api key"
$serial = "serial number"
$url = "https://api.meraki.com/api/v1/devices/$serial/switch/ports"
$headers = @{
"X-Cisco-Meraki-API-Key" = $apiKey
"Accept" = "application/json"
}
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
$response
Output:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:7 char:13
+ $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Instead of using the X-Cisco-Meraki-API-Key, use this as your authentication header.
{
"Authorization": "Bearer <Meraki_API_Key>"
}
I can't really read your screenshot, but some of the APIs don't work unless you also specify the content encoding with a header something like:
Accept: application/json
You should be specifying this for all Meraki API calls.
I have tried but same error below is the script and output:
script:
$apiKey = "api key"
$serial = "serial number"
$url = "https://api.meraki.com/api/v1/devices/$serial/switch/ports"
$headers = @{
"X-Cisco-Meraki-API-Key" = $apiKey
"Accept" = "application/json"
}
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
$response
Output:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:7 char:13
+ $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand