API Writing to Custom Fields via Python

359 views
Skip to first unread message

Scrounger117

unread,
Jul 16, 2020, 11:53:12 PM7/16/20
to NetBox
I'm using the Python Netbox library  https://pypi.org/project/python-netbox/ and attempting to write information to a custom_field that is associated with tenants.  Unable to figure out the correct syntax for entering information into my custom field named "custshortname" in this example:

.tenancy.create_tenant(name='Big Company', slug='big-company', custshortname='bigco')

The tenant creates, but the custom_field remains unpopulated.  Of course, I can enter the information in the gui, and getting the response via JSON in Python shows this for another customer:

, 'custom_fields': {'custshortname': 'medco',

Anyone had any success in getting this to work?  I've also tried pynetbox as well, same basic issue, can't write to custom_fields.  Thanks.

Markku Leiniö

unread,
Jul 17, 2020, 5:40:41 AM7/17/20
to NetBox
Hi, in Pynetbox:

big_tenant = netbox.tenancy.tenants.create(name="BC", slug="bc", custom_fields={"custshortname": "b"})

Markku

Scrounger117

unread,
Jul 17, 2020, 2:12:14 PM7/17/20
to NetBox
@Markku

That worked for me perfectly, in both pynetbox and the python-netbox library.  Thank you for your help and contribution.

Mike
Reply all
Reply to author
Forward
0 new messages