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:
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
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.
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 🙂
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). 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.
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/...