Trouble Renaming Devices via Postman

Solved
rossbryant
Conversationalist

Trouble Renaming Devices via Postman

Hello,

I'm trying to follow instructions for Postman to bulk update device names based on their serial number.  I keep getting a 502 Bad Gateway error. I'm able to run different commands for getting my Organization and Network IDs so I know what I'm doing is partially working, I just can't get to the finish line. I'm hoping someone here can help. I have an open ticket with Meraki but it has gone quiet.

 

My most recent attempts have been using a fork of the public Meraki Dashboard API - v1.10. This is the PUT command:

{{baseUrl}}/networks/:networkId/sm/devices/fields?serial={{serial}}&deviceFields={"name":{{name}}"}

 

My networkID is set as a variable as well as my X-Cisco-Meraki-API-Key Header.

 

Here is the Code Snippet from Postman if that's helpful, with my network ID and API Key X'd out.

 

import requests
import json

url = "https://api.meraki.com/api/v1/networks/N_5XXXXXXXXXXXXX5/sm/devices/fields?serial=&deviceFields={\"name\":{{name}}\"}"

payload = json.dumps({
  "deviceFields": {
    "name": "<string>",
    "notes": "<string>"
  },
  "wifiMac": "<string>",
  "id": "<string>",
  "serial": "<string>"
})
headers = {
  'X-Cisco-Meraki-API-Key': 'fXXXXXXXXXXXXXXXXXXXXXXXXX3',
  'Content-Type': 'application/json'
}

response = requests.request("PUT", url, headers=headers, data=payload)

print(response.text)

 

 

When I run the collection I'm using a CSV file with a serial column and name column. A single entry for testing. This is what the data preview looks like:

rossbryant_0-1624628375972.png

 

Thanks for any suggestions,

Ross

 

1 Accepted Solution
EncinitasMatt
Here to help

I got the following to work using "Modify the fields of a device" 

 

Leave the Params unchanged.  Enter your networkid in the Path Variables

{{baseUrl}}/networks/:networkId/sm/devices/fields

 

Go to the Body and modify it, adding bracketed entries to match the headers in your CSV file.

{
    "deviceFields": {
        "name": "{{name}}"
    },
    "serial": "{{serial}}"
}

 

This video provided me with the idea.  https://www.youtube.com/watch?v=wjPmW-EIpTw&t=202s

 

View solution in original post

5 Replies 5
EncinitasMatt
Here to help

I am trying to do this same thing but I'm a Postman noob.  I found this article for the older API version.

 

https://documentation.meraki.com/SM/Other_Topics/Renaming_Systems_Manager_Client_Devices_with_a_.csv...

 

 

rossbryant
Conversationalist

Thanks. That's where I started out but was getting the same error so I started expanding my search and found the newer API version but with the same results unfortunately.

 

Are you getting the same error? 502 Bad Gateway?

EncinitasMatt
Here to help

I'm attempting to edit the existing "Modify the fields of a device" under PRODUCTS > sm > Configure > Fields.

I'm not bothering with the CSV file part yet, I'm just trying to get it to work by filling in the fields for one device.

 

{{baseUrl}}/networks/:networkId/sm/devices/fields?serial=&name=

 

After filling in the fields it will look like this, pulling the networkId from a path variable.

{{baseUrl}}/networks/:networkId/sm/devices/fields?serial=xxxxxxxxxx&name=RenameTest

 

The error I get is 400 bad syntax.

Reply body is:

{"errors":["Invalid parameters(s): name"]}

EncinitasMatt
Here to help

I got the following to work using "Modify the fields of a device" 

 

Leave the Params unchanged.  Enter your networkid in the Path Variables

{{baseUrl}}/networks/:networkId/sm/devices/fields

 

Go to the Body and modify it, adding bracketed entries to match the headers in your CSV file.

{
    "deviceFields": {
        "name": "{{name}}"
    },
    "serial": "{{serial}}"
}

 

This video provided me with the idea.  https://www.youtube.com/watch?v=wjPmW-EIpTw&t=202s

 

rossbryant
Conversationalist

Thank you! This worked. I did have to set the Body to Raw - JSON for it to work though. It went in as Raw - Text at first which did not work. I noticed it was JSON in the video you posted so I tried that and it worked!

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