API url for getting the details of AP connected to which port?

Paramehswari
Comes here often

API url for getting the details of AP connected to which port?

I used but getting bad request below is the screenshot:

Paramehswari_0-1714472342459.png

 

Could you please help me in this

5 Replies 5
rhbirkelund
Kind of a big deal

The base url should be api.Meraki.com, and not your shard url.

LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.

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

Paramehswari_0-1714539629353.png

 

Instead of using the X-Cisco-Meraki-API-Key, use this as your authentication header.

{
 "Authorization": "Bearer <Meraki_API_Key>"
}
LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.
PhilipDAth
Kind of a big deal
Kind of a big deal

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

Paramehswari_1-1714539802294.png

 

Get notified when there are additional replies to this discussion.