API returning 404

SOLVED
Michael-873494
Here to help

API returning 404

I am trying to leverage the API to write a script that will periodically check the last connected date for our SM devices.

 

I happen to be using Powershell, though you tell me if it matters and I still consider myself a bginner when it comes to REST, but I have worked with it.

 

My first issue is that I'm not sure what format the network id should be in. My network ID is something like 123-456-0789, so I tried that in the URL and I also tried 1234560789, but neither made any difference.

 

Below is my code, followed by the error I am seeing:

    $MerakiApiKey = "32d000fa9c0ce60d4e000cd4d00001b00000053d"
    $MerakiUrl = "https://api.meraki.com/api/v0/networks/1234560789/sm/devices?fields=ip,lastConnected&scope=all"
    $headers = @{}
    $headers.Add("X-Cisco-Meraki-API-KEY",$MerakiApiKey)
    $headers.Add("Content-Type","application/json")
Invoke-RestMethod -Method Get -Uri $MerakiUrl -Headers $headers

Error:

Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At line:1 char:1
+ Invoke-RestMethod -Method Get -Uri $MerakiUrl -Headers $headers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

1 ACCEPTED SOLUTION
hoempf
Getting noticed

HI Michael

The network id is not the ID you see in the dashboard or somewhere else, you can get it by listing networks from your org with a call to:

/organizations/[organizationId]/networks

You can get a list of orgs you manage by calling:

/organizations

Also please change your API key *now* since you posted it here and everyone with that key can now access your network via API and make changes (!)

The network ID looks similar to: L_123456789123456789


Cheers!

View solution in original post

7 REPLIES 7
hoempf
Getting noticed

HI Michael

The network id is not the ID you see in the dashboard or somewhere else, you can get it by listing networks from your org with a call to:

/organizations/[organizationId]/networks

You can get a list of orgs you manage by calling:

/organizations

Also please change your API key *now* since you posted it here and everyone with that key can now access your network via API and make changes (!)

The network ID looks similar to: L_123456789123456789


Cheers!

I was wondering about the OrgID and Network ID, but I didn't see where to get them. Thank you very much!

 

That API key isn't the real one, no worries!

 

Now the error I see is:

Server error
The server encountered an error and could not complete your request. A message has been sent to our engineering and support teams to notify us of the problem, and we will fix it as soon as possible.
The Cisco Meraki Dashboard is temporarily unavailable, but rest assured your Meraki equipment is still running and network operation has not been interrupted. Learn more about Meraki's out-of-band control.
 

Awesome, glad to hear about the API key 😉

 

So either the Meraki server where your org is hosted really has problems now or you malformed the request. In the latter case I think you should get another error, but not sure since it never failed on me with this error message 🙂

 

Also you might want to consider using the shard URL like "n172.meraki.com" instead of "api.meraki.com". In my experience using the shard node directly works better than following redirects.

 

I hope that helps 🙂

 

Cheers!

 

P.S. Do not worry too much about REST, the API is IMHO fundamentally not RESTful on so many levels (that's a whole different topic[1]). I think it's better to call it JSON API over HTTPS for a better understanding on how it works. Basically you throw JSON at it and it replies in JSON, pretty basic. It's not worse or better than a real REST API, just a different approach.

 

[1] https://dzone.com/articles/5-easy-to-spot-tells-that-your-rest-api-is-not-res 

I did try the shared url and got the same error. I will try again tomorrow I guess and see if it changes.

 

Based on the code I posted, do you see anything that should make it malformed?

 

 

I don‘t have a lot of experience with Powershell but I‘d say it looks good so far.
AlexG
Getting noticed

@Michael-873494

 

We utilize the API exclusively with PS in our environment and I do not see an issue with your code. You would want to try the shard URL as previously suggested as well as https://dashboard.meraki.com/api/... 

The final issue I had, turned out to have to do with the "scope=All". Adding the scope parameter causes the error I reported, though I am not sure why and tech support doesn't know either.

Get notified when there are additional replies to this discussion.