Creating a Record

New Records can be created using an Endpoint’s create() method. All fields supported by the Model in Nautobot can be passed into the method, and every required field must be passed.

nautobot = api(url=url, token=token)
device_roles = nautobot.dcim.device_roles

# Create a dict of keyword arguments to use for device role config.
access_role_config = {
    "name": "Access Switch",
    "slug": "access-switch",

# Create a new Record in the Device Roles Model.
access_role = device_roles.create(**access_role_config)

The create() method adds a new Record into the Nautobot database, and a representative Record object is returned. This record object has attributes for each field in the database table. The following code block is a continuation of the previous one.

>>> # Show that fields passed to the create method
>>> # are accessible attributes with expected values
'Access Switch'
>>> access_role.slug

>>> # Show that fields not passed to the method
>>> # were assigned values by the Model
>>> access_role.description