'prefix': ['This field is required.'] error using put api thru python

598 views
Skip to first unread message

sreeram haridas

unread,
Apr 4, 2019, 3:27:25 PM4/4/19
to NetBox
This is the code im trying to use for updating description for an existing prefix
url_test = /api/ipam/prefixes/{id}

r = requests.put(
url_test,
headers=headers,
data={'prefix': cidr, 'description': 'test'})

and im receiving the following
<Response [400]>
{'prefix': ['This field is required.']}

Is this correct?

Jeremy Stretch

unread,
Apr 4, 2019, 3:55:11 PM4/4/19
to sreeram haridas, NetBox
Yes, this is correct. PUT requests require a full representation of the object. To make a partial update, use PATCH.

Jeremy

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/23f4cd4c-9b47-4770-9060-d5c9cac98d06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sreeram haridas

unread,
Apr 4, 2019, 4:47:15 PM4/4/19
to NetBox
SO Im getting 400 error and the response still doesnt have the description field updated.

This is what im looking at
{
    "id": 2083,
    "family": 4,
    "prefix": "10.220.82.0/23",
    "site": null,
    "vrf": null,
    "tenant": null,
    "vlan": null,
    "status": {
        "value": 2,
        "label": "Reserved"
    },
    "role": {
        "id": 6,
        "url": "http://xxxx/api/ipam/roles/6/",
        "name": "AWS-CLIENT-VPC-OPTIONS",
        "slug": "aws-client-vpc-options"
    },
    "is_pool": false,
    "description": "",
    "custom_fields": {}
}

Output response is 
<Response [400]>
{'prefix': ['This field is required.']}

What does this mean

On Thursday, 4 April 2019 15:55:11 UTC-4, Jeremy Stretch wrote:
Yes, this is correct. PUT requests require a full representation of the object. To make a partial update, use PATCH.

Jeremy

On Thu, Apr 4, 2019 at 3:27 PM sreeram haridas <sreera...@gmail.com> wrote:
This is the code im trying to use for updating description for an existing prefix
url_test = /api/ipam/prefixes/{id}

r = requests.put(
url_test,
headers=headers,
data={'prefix': cidr, 'description': 'test'})

and im receiving the following
<Response [400]>
{'prefix': ['This field is required.']}

Is this correct?

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-...@googlegroups.com.

Brian Candler

unread,
Apr 4, 2019, 5:54:46 PM4/4/19
to NetBox
This is python, right?  I think you need json= rather than data=

r = requests.patch(
    url_test,
    headers=headers,
    json={'prefix': cidr, 'description': 'test'})


Also, you'll need the trailing slash after the id - e.g. /api/ipam/prefixes/1/

There is a Python Netbox library you can use which you might prefer, see
Reply all
Reply to author
Forward
0 new messages