Update client policy with API using Google script

Ike
Just browsing

Update client policy with API using Google script

I would like to update the group policy of a client using API in a google script.

There is a nice API that should do the work: "Update Network Client Policy". In the google script I am using the UrlFetchApp.fetch() function to do the job.
However, when I call this function with the correct values, the response is 200 (OK), but the policy is not actually changed. Using the same parameters in the Meraki Tool, the policy is correctly changed. So parameters are OK.

Can anyone give me a hint where I go wrong?

The script is as follows

var apiKey = <key>

var networkId = < networkId>

var clientId = <clientId>

var url =  'https://api.meraki.com/api/v0/networks/'+ networkId+'/clients/'+ clientId+'/policy'

var body = {
  "mac": <mac address>,
  "devicePolicy": "Normal"
}.

var headers = {

  "Content-Type" : "application/json",

  "X-Cisco-Meraki-API-Key" : apiKey

}

var options = {

  "method" : "PUT",

  "headers" : headers,

  "payload" : JSON.stringify(body),

}

var response = UrlFetchApp.fetch(url, options)

var responseCode = response.getResponseCode()

var responseMessage = JSON.parse(response.getContentText())

 

After execution:

 

responseCode = 200

responseMessage = {

  "mac" : <mac address>
  "type" : "Blocked"

}

 

So, no change in the policy.

   

 

 

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

You'll need followRedirects enabled.

https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app 

 

 

Scratch that - I see it is enabled by default.

PhilipDAth
Kind of a big deal
Kind of a big deal

Try retrieving an existing device policy and see how that JSON is formatted.

Thanks for your answer.

Would be great to retreive the struct, but I don't know how to do that. 
Using the Meraki tool the API call can be made online. And you can see the struct that is supposed to be used.
And it works. But I cannot find out the exact syntax the tool is using. Apparently it is not the same: theirs is working, mine is not..
 
Get notified when there are additional replies to this discussion.