CLI API Question

333 views
Skip to first unread message

Jason Kopacko

unread,
Aug 29, 2017, 10:03:52 PM8/29/17
to NetBox
I am wanting to do a bulk update on devices but I cannot seem to get the command correct. I get this error:

{
    "device_role": [
        "This field is required."
    ],
    "site": [
        "This field is required."
    ],
    "device_type": [
        "This field is required."
    ]
}


So I know my ignorance to what I am doing is playing a big part but I cannot seem to pass all the required fields correctly.

For example, the site is #21, the device_role is #1, and the device_type is #1 as well. Any advice or examples that give a full set of required options would be really nice.

My base command looks like this:

curl -X PUT -H "Authorization: Token ####" -H "Accept: application/json; indent=4" http://####/api/dcim/devices/424/ --data

For example, I'm trying to update the serial numbers.

'{"serial": "####"}'

Thanks in advance.

Jeremy Stretch

unread,
Aug 30, 2017, 9:19:37 AM8/30/17
to Jason Kopacko, NetBox
Use PATCH instead of PUT. PUT requires defining all required fields; PATCH updates an object in place.

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-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/d3a69de2-07f8-43cf-a7ca-a9a03c4560a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Kopacko

unread,
Aug 30, 2017, 9:53:45 AM8/30/17
to NetBox
Ok so I can use patch and just, for example, update the serial number of a device?

I will try it here momentarily.


On Wednesday, August 30, 2017 at 8:19:37 AM UTC-5, Jeremy Stretch wrote:
Use PATCH instead of PUT. PUT requires defining all required fields; PATCH updates an object in place.

Jeremy
On Tue, Aug 29, 2017 at 10:03 PM, Jason Kopacko <ja...@kopacko.com> wrote:
I am wanting to do a bulk update on devices but I cannot seem to get the command correct. I get this error:

{
    "device_role": [
        "This field is required."
    ],
    "site": [
        "This field is required."
    ],
    "device_type": [
        "This field is required."
    ]
}


So I know my ignorance to what I am doing is playing a big part but I cannot seem to pass all the required fields correctly.

For example, the site is #21, the device_role is #1, and the device_type is #1 as well. Any advice or examples that give a full set of required options would be really nice.

My base command looks like this:

curl -X PUT -H "Authorization: Token ####" -H "Accept: application/json; indent=4" http://####/api/dcim/devices/424/ --data

For example, I'm trying to update the serial numbers.

'{"serial": "####"}'

Thanks in advance.

--
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.

Jason Kopacko

unread,
Aug 30, 2017, 10:09:54 AM8/30/17
to NetBox
Ok so I do not get an error but the serial field does not get updated.

curl -X PATCH -H "Authorization: Token ####" -H "Accept: application/json; indent=4" http://####/api/dcim/devices/424/ --data '{ "serial": "####" }'

Is the exact command I used.

Jason Kopacko

unread,
Aug 30, 2017, 6:02:39 PM8/30/17
to NetBox
Jeremy or any one else?

Jason Kopacko

unread,
Aug 31, 2017, 10:48:45 AM8/31/17
to NetBox
I think I managed to hack my way to something that worked for updating specific fields.
Reply all
Reply to author
Forward
0 new messages