Errors using API for "Update Network Client Policy"

oemunlock
Conversationalist

Errors using API for "Update Network Client Policy"

I have a MX64 and am trying to use the Meraki API for updating a policy following the directions here: https://developer.cisco.com/meraki/api-v1/#!update-network-client-policy

 

I get a 400 error If I send a PUT request for one of the clients on my network with whatever combination of mac, devicePolicy or groupPolicyID such as:

 

PUT /api/v1/networks/[MY_NETWORK_ID]/clients/[MY_CLIENT_ID]/policy HTTP/1.1
Host: [MERAKI_HOST_HERE]
X-Cisco-Meraki-API-Key: [REDACTED]
Accept-Language: en-US,en;q=0.9
Connection: close
Content-Length: 31

{
    "groupPolicyId": "100"
}

 

The error message is verbatim as follows (note that the networkId and clientId are not printed in the error message):

 

HTTP/1.1 400 Bad Request
Server: nginx

[TRUNCATED HEADER]
Date: Sat, 04 Dec 2021 21:53:49 GMT

{"errors":["Error for /networks/{networkId}/clients/{clientId}/policy: None of the fields ('devicePolicy' or 'groupPolicyId') were specified."]}

 

I am certain I have the right client and network ID since I am able to use a GET request.

 

GET /api/v1/networks/[MY_NETWORK_ID]/clients/[MY_CLIENT_ID]/policy HTTP/1.1
Host: [MERAKI_HOST_HERE]
X-Cisco-Meraki-API-Key: [REDACTED]
Accept-Language: en-US,en;q=0.9
Connection: close
Content-Length: 2

 

and I am getting valid data for my specific client ID (200 OK).

 

The API indicating the mac address is needed aside, I feel am I missing something simple. Anyone have a suggestion?

4 Replies 4
Brash
Kind of a big deal
Kind of a big deal

It looks like you haven't specified "devicepolicy" in the body.

 

Device Policy

The policy to assign. Can be 'Whitelisted', 'Blocked', 'Normal' or 'Group policy'. Required.

 

Assumedly for your API call, it should be set to "Group policy"

oemunlock
Conversationalist

Same error after adding device policy in the body:

 

PUT /api/v1/networks/[MY_NETWORK_ID]/clients/[MY_CLIENT_ID]/policy HTTP/1.1
Host: [MERAKI_HOST_HERE]
X-Cisco-Meraki-API-Key: [REDACTED]
Accept-Language: en-US,en;q=0.9
Connection: close
Content-Length: 66

{
"devicePolicy": "Group policy",
"groupPolicyId": "104"
}

 

Result was:

 

HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 06 Dec 2021 01:21:15 GMT
Content-Type: application/json; charset=utf-8
Connection: close
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
X-Frame-Options: sameorigin
X-Robots-Tag: none
X-UA-Compatible: IE=Edge,chrome=1

[TRUNCATED]

Content-Length: 144

{"errors":["Error for /networks/{networkId}/clients/{clientId}/policy: None of the fields ('devicePolicy' or 'groupPolicyId') were specified."]}

Brash
Kind of a big deal
Kind of a big deal

Looks like you've got the parameters correct.
Potentially your JSON body is malformed (end of line character or other hidden character causing issues)?


I just did a quick test using Postman.

PUT:
.../v1/networks/<NetworkID</clients/<clientID>/policy


Body:

{
    "devicePolicy""Group policy",
    "groupPolicyId""100"
}

Response:
{
    "mac""<Mac Address>",
    "groupPolicyId""100",
    "devicePolicy""Group policy"
}
oemunlock
Conversationalist

Thanks for the brainstorming with me, @Brash . Your comment on looking at the JSON helped me troubleshoot. I was missing the header "Content-Type: application/json".

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.
Labels