cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bad request: There was a problem in the JSON you submitted

SOLVED
Highlighted
Conversationalist

Bad request: There was a problem in the JSON you submitted

Hi,

 

I've written a function using Google Apps Script to create an organization in Meraki but received above error saying there's a problem in the JSON.

I was able to GET data from Meraki but unable to PUT data using below format.

Any advice why this is happening?

 

 

function createOrg(orgName)
{
  var org = 
      {
        "name": orgName
      };
  var URL = "<a href="https://api.meraki.com/api/v0/organizations" target="_blank">https://api.meraki.com/api/v0/organizations</a>";
  var params = 
      {
        headers:
        {
          "X-Cisco-Meraki-API-Key": settings.apiKey, 
          "Content-Type": "application/json", 
          "Accept": "*/*"
        },
        method: "PUT",
        payload: org,
        muteHttpExceptions: true
      }
  var response = UrlFetchApp.fetch(URL, params);
  Logger.log(response);
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kind of a big deal

Re: Bad request: There was a problem in the JSON you submitted

A few things. The create org call is supposed to be a POST instead of PUT.

 

I noticed that you need to apply a function to the payload:

payload: JSON.stingify(org)

 

Replace the baseURL with the actual shard you are on. Google script does not seem to follow the redirect. E.g. https://n248.meraki.com/api.... instead of https://api.meraki.com ... More info about that issue here: https://documentation.meraki.com/zGeneral_Administration/Other_Topics/The_Cisco_Meraki_Dashboard_API... (look for the section about redirection)

 

So this works for me:

function createOrg(orgName)
{
  var org = 
      {
        "name": "Google Apps Org 2"
      };
  var URL = "https://<myshardid>.meraki.com/api/v0/organizations";
  var params = 
      {
        headers:
        {
          "X-Cisco-Meraki-API-Key": "<myAPIkey>", 
          "Content-Type": "application/json", 
          "Accept": "*/*"
        },
        method: "POST",
        payload: JSON.stringify(org),
        muteHttpExceptions: true
      }
  var response = UrlFetchApp.fetch(URL, params);
  Logger.log(response);
}

 

2 REPLIES 2
Kind of a big deal

Re: Bad request: There was a problem in the JSON you submitted

A few things. The create org call is supposed to be a POST instead of PUT.

 

I noticed that you need to apply a function to the payload:

payload: JSON.stingify(org)

 

Replace the baseURL with the actual shard you are on. Google script does not seem to follow the redirect. E.g. https://n248.meraki.com/api.... instead of https://api.meraki.com ... More info about that issue here: https://documentation.meraki.com/zGeneral_Administration/Other_Topics/The_Cisco_Meraki_Dashboard_API... (look for the section about redirection)

 

So this works for me:

function createOrg(orgName)
{
  var org = 
      {
        "name": "Google Apps Org 2"
      };
  var URL = "https://<myshardid>.meraki.com/api/v0/organizations";
  var params = 
      {
        headers:
        {
          "X-Cisco-Meraki-API-Key": "<myAPIkey>", 
          "Content-Type": "application/json", 
          "Accept": "*/*"
        },
        method: "POST",
        payload: JSON.stringify(org),
        muteHttpExceptions: true
      }
  var response = UrlFetchApp.fetch(URL, params);
  Logger.log(response);
}

 

Conversationalist

Re: Bad request: There was a problem in the JSON you submitted

@BrechtSchampthank you so much for your advice, I was able to create the organization successfully.

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.