Create organization [POST] returns list of organizations [GET]

niciolas-rpamak
Just browsing

Create organization [POST] returns list of organizations [GET]

I am using meraki api to create organizations , i am expecting to recieve the response of the post method, instead i recieve a redirect to get, i am using the same template that meraki gives you in the documentation the https://developer.cisco.com/meraki/api-v1/#!create-organization

 

I found here something regarding  this https://documentation.meraki.com/General_Administration/Other_Topics/Cisco_Meraki_Dashboard_API 

Note also that most HTTP libraries and clients will not follow a redirect with an HTTP verb other than GET, and may instead follow the redirect but substitute GET for the HTTP verb. As a result, you may find a redirect on DELETE, POST, or PUT will look as though a GET was requested. To avoid this, first perform a GET on the organization you are working with and store the URL you are working with, then use that URL for subsequent requests (particularly those that modify state).

 

I dont entirely understand what this means, or how i can fix it.

 

This is the template i am using form the meraki page, i am working with node js, also tried with axios and i am getting similar error.

 

var request = require('request');

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"X-Cisco-Meraki-API-Key": ""
}
body = `{ "name": "My organization" }`;

var options = {
method: 'POST',
url: 'https://api.meraki.com/api/v1/organizations',
headers,
body,
};

request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});

 

 

If anyone can provide any help or guidance on how to resolve this it would be great, thanks

3 Replies 3
PhilipDAth
Kind of a big deal
Kind of a big deal

The problem is "POST" is considered an unsafe HTTP method by many libraries when following a redirect.  So the library automatically changes it to a GET (which is considered safe) and breaks things.

 

Try Googling something like "python requests follow POST redirect".  requests will have some flag or method you can use to override this behaviour.  I have run into it before, but it was so long ago I don't remember the solution.

 

 

The easier solution is to instead use the Cisco Meraki Python SDK and then you can forget about these kinds of issues.

I am using nodejs with axios, but with requests (also node) its the same problem

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.