API - (PUT or PATCH) /dcim/devices/ #4438

Closed
opened 2025-12-29 18:35:59 +01:00 by adam · 3 comments
Owner

Originally created by @RomainGarel on GitHub (Jan 6, 2021).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.10.2
  • CentOS Linux release 8.2.2004

Steps to Reproduce

  1. using a existing "Device"
  2. try to change a field value using PATCH method (for example the status)
  3. Or simply using netbox API swagger

Expected Behavior

With this request:
curl --location --request PATCH 'https://x.x.x.x/api/dcim/devices/'
--header 'Authorization: Token xxxxxxxxx'
--header 'Content-Type: application/json'
--header 'Accept: application/json; indent=4'
--data-raw ' {
"name": "sr-nbi-ones-test",
"device_type": 1,
"device_role": 1,
"site": 1,
"status": "failed"
}'
The status have to change to failed, but it's not working.
Same thing using swagger (see screenshot below).
I tried also using Postman and Ansible...

Observed Behavior

Answer is always "400 Bad Resquest"
{
"non_field_errors": [
"Expected a list of items but got type "dict"."
]
}

Originally created by @RomainGarel on GitHub (Jan 6, 2021). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reporting reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.10.2 * CentOS Linux release 8.2.2004 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. using a existing "Device" 2. try to change a field value using PATCH method (for example the status) 3. Or simply using netbox API swagger <!-- What did you expect to happen? --> ### Expected Behavior With this request: curl --location --request PATCH 'https://x.x.x.x/api/dcim/devices/' \ --header 'Authorization: Token xxxxxxxxx' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json; indent=4' \ --data-raw ' { "name": "sr-nbi-ones-test", "device_type": 1, "device_role": 1, "site": 1, "status": "failed" }' The status have to change to failed, but it's not working. Same thing using swagger (see screenshot below). I tried also using Postman and Ansible... <!-- What happened instead? --> ### Observed Behavior Answer is always "400 Bad Resquest" { "non_field_errors": [ "Expected a list of items but got type \"dict\"." ] }
adam closed this issue 2025-12-29 18:36:00 +01:00
Author
Owner

@RomainGarel commented on GitHub (Jan 6, 2021):

ScreenShot131

@RomainGarel commented on GitHub (Jan 6, 2021): ![ScreenShot131](https://user-images.githubusercontent.com/36295219/103772198-6434df80-5029-11eb-98bb-5167e96d50a6.jpg)
Author
Owner

@lampwins commented on GitHub (Jan 6, 2021):

You are sending a single object to the list endpoint /api/dcim/devices/. You have two options, use the bulk functionality of the list endpoint by sending your data as a JSON list that contains one object, or use the single object detail view for PUT/PATCH. This is done by appending the ID of the single object you want to work with to the URL: /api/dcim/devices/123/

@lampwins commented on GitHub (Jan 6, 2021): You are sending a single object to the list endpoint `/api/dcim/devices/`. You have two options, use the bulk functionality of the list endpoint by sending your data as a JSON list that contains one object, or use the single object detail view for PUT/PATCH. This is done by appending the ID of the single object you want to work with to the URL: `/api/dcim/devices/123/`
Author
Owner

@RomainGarel commented on GitHub (Jan 6, 2021):

Oh... sorry...
Thanks for your answer

@RomainGarel commented on GitHub (Jan 6, 2021): Oh... sorry... Thanks for your answer
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4438