Updating Records¶
Modifying the data in a Record <Terminology>
{.interpreted-text
role="ref"} is accomplished by using a Record\'s
~pynautobot.core.response.Record.update
{.interpreted-text
role="py:meth"} method. This method accepts a dictionary of field/value
mappings (Ex: {\"description\": \"Provides access to end hosts\"}). A
boolean is returned to indicate whether updates were made to the Record.
The below example shows retrieving a record using the
~pynautobot.core.endpoint.Endpoint.get
{.interpreted-text
role="py:meth"} method, and then updating
fields <Terminology>
in the returned
Record <pynautobot.core.response.Record>
{.interpreted-text
role="py:class"} object.
>>> nautobot = api(url=url, token=token)
>>> roles = nautobot.extras.roles
>>>
>>> # Get the record object for the access-switch role
>>> access_role = roles.get(name="Access Switch")
>>>
>>> # Show existing values for name and description fields
>>> access_role.name
'Access Switch'
>>> access_role.description
''
>>>
>>> # Create a dictionary to update the role fields
>>> access_switch_updates = {
... "name": "access switch",
... "description": "Provides access to end hosts",
... }
>>>
>>> # Show using the update method on the role
>>> access_role.update(access_switch_updates)
True
>>>
>>> # Show that the fields were updated on the existing role
>>> access_role.name
'access switch'
>>> access_role.description
'Provides access to end hosts'