How to add a tag without losing the information that was there before?

Kenneth_rf
Here to help

How to add a tag without losing the information that was there before?

Hello,

 

I am trying to make an UPDATE of certain ports of all the switches in our organization so that they are managed via port_management.

 

I am doing tests and when carrying out the update I have noticed that the configuration that I had before is loaded, that is, I lose the tag that was there before but my intention is to keep it.

 

Any solution via API?

 

Regards,

2 Replies 2
sungod
Kind of a big deal

In general, where you want to use the API to 'update' an existing element by adding/removing one or more items in it, the method to use is...

 

Read the value of the element into a local variable.

 

Make the required changes to that local copy.

 

Write the updated element value back.

 

ls08
Here to help

sungod has it nailed

in python the code below will do what OP is looking

 

import meraki

API_KEY = "API-KEY-HERE"
dashboard = meraki.DashboardAPI(API_KEY,suppress_logging=True)
 
response = dashboard.networks.getNetwork(
    network_id
)

#This looks for existing tags and stores it into local variable
updated_tags = response['tags']

#Below adds two tags.
updated_tags.append('WIFI')
updated_tags.append('NEW YORK')

#Finally update the network with the tag. Keeps the existing tags and adds the two I mentioned.

response = dashboard.networks.updateNetwork(
    network_id,
    tags=updated_tags
)

print(response)
Get notified when there are additional replies to this discussion.