powershell REST API issue with Meraki Dashboard API

RajeevElzrando
Just browsing

powershell REST API issue with Meraki Dashboard API

I'm having a problem with a specific REST api from meraki. I have been able to perform all the get operations with success, however the POST operations I am receiving a "308" error from the server. I'm trying to do the following:

Example request:

curl -L -H 'X-Cisco-Meraki-API-Key: <key>' -X POST -H 'Content-Type: 
application/json' --data-binary '{"name":"Miles Meraki", 
"email":"miles@meraki.com", "orgAccess":"none", "tags":[{"tag":"west", 
"access":"read-only"}]}' 
'https://dashboard.meraki.com/api/v0/organizations/1234/admins'

My Request:

Invoke-RestMethod -Method Post -Uri 
https://dashboard.meraki.com/api/v0/organizations/$global:MerakiOrg/admins/ -
Body $jbody -Headers $Global:MerakiHeader -ContentType 'application/json'

My $jbody value is the literal copied json from the example. I'm not familiar with this 308 code as a return code. Any guidance would be very helpful.

4 Replies 4
GreenMan
Meraki Employee
Meraki Employee

Not sure whether it's the specific cause of this problem (my guess would be Yes), but I notice you're using a V0 endpoint.   V0 is no longer supported - I'd suggest you move to V1 endpoints for all the calls in your script(s).   In this case:   https://developer.cisco.com/meraki/api-v1/#!get-organization-admins

sungod
Head in the Cloud

308 means 'permanent redirect', the -L option in the curl command tells it to obey redirects.

 

For instance, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

 

I'd assume that your powershell code isn't handling redirects when it gets a 308.

 

Also, as mentioned above, you are using the v0 API, I really recommend you use v1 instead.

 

See https://community.meraki.com/t5/Developers-APIs/Dashboard-API-v0-End-of-Support-Sunset-amp-Grace-Per...

 

JasonM
Meraki Employee
Meraki Employee

In addition to the other great comments here, it looks like it is doing a redirect because your base URL is https://dashboard.meraki.com rather than https://api.meraki.com. Try changing the base URL and see what that results in.

Crocker
Building a reputation

I've run into this a few times, and it seems to only occur when performing a POST or PUT via Invoke-RestMethod. My GETs via Invoke-RestMethod tend to work as expected. You can try to specify -maximumredirection ## (default value is 5) to get around this, though I'm not sure if it'll work - can't remember if I fiddled with this or not.

 

I kludged my scripts to point directly to the shard I'm on - n426.meraki.com/api/v1/. It's not recommended, and I'm sure this will bite me at some point.

 

 

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.