REST API returns HTTP 400 with no details other than "Bad request for URL https://netbox.example.com/..." #4170

Closed
opened 2025-12-29 18:33:36 +01:00 by adam · 6 comments
Owner

Originally created by @jogulin on GitHub (Oct 7, 2020).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.9.3

Proposed Functionality

object.put() fails with an HTTP 400 "Bad Request" but does not give a reason why it is a bad request. Information of how to fix it would be helpful (e.g., "object.data_field cannot be empty")

Use Case

Automated daily import/update of vCenter information in bulk to Netbox that assigns clusters, interfaces, IP addresses.
Automated import of inventory data from data center audits to include rack locations, sites, serial numbers, asset tags, etc.

Database Changes

If attempting to update a record and a "not null" field is "null" then this must be captured and returned with the error

External Dependencies

None of which I am aware at the time I write this

Originally created by @jogulin on GitHub (Oct 7, 2020). ### Environment * Python version: 3.6.8 * NetBox version: 2.9.3 ### Proposed Functionality object.put() fails with an HTTP 400 "Bad Request" but does not give a reason why it is a bad request. Information of how to fix it would be helpful (e.g., "object.data_field cannot be empty") ### Use Case Automated daily import/update of vCenter information in bulk to Netbox that assigns clusters, interfaces, IP addresses. Automated import of inventory data from data center audits to include rack locations, sites, serial numbers, asset tags, etc. ### Database Changes If attempting to update a record and a "not null" field is "null" then this must be captured and returned with the error ### External Dependencies None of which I am aware at the time I write this
adam closed this issue 2025-12-29 18:33:36 +01:00
Author
Owner

@DanSheps commented on GitHub (Oct 7, 2020):

Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v2.9.4. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@DanSheps commented on GitHub (Oct 7, 2020): Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v2.9.4. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
Author
Owner

@jogulin commented on GitHub (Oct 7, 2020):

If I go into the Postgres database behind netbox, I find in the ipam_ipaddresses table the fact that "description" and "dns_name" are listed as being "not null"... this is exactly the kind of thing that should be returned when using the REST API when I attempt to update a record and the items in question are not present when using the HTTP PUT operation.

@jogulin commented on GitHub (Oct 7, 2020): If I go into the Postgres database behind netbox, I find in the ipam_ipaddresses table the fact that "description" and "dns_name" are listed as being "not null"... this is exactly the kind of thing that should be returned when using the REST API when I attempt to update a record and the items in question are not present when using the HTTP PUT operation.
Author
Owner

@jeremystretch commented on GitHub (Oct 7, 2020):

The NetBox REST API does inform you when required fields are absent, but this can only happen if it understands the request to begin with. For example, if I try to create an IP address without specifying its address, the error message is quite clear.

$ curl -X POST \
> -H "Authorization: Token $TOKEN" \
> -H "Content-Type: application/json" \
> -H "Accept: application/json; indent=4" \
> http://localhost:8000/api/ipam/ip-addresses/ \
> --data '{"description": "foo"}'
{
    "address": [
        "This field is required."
    ]
}

If you're not seeing these validation errors, it's because NetBox doesn't understand the request to begin with. This is likely because the request data is encoded wrong or badly formatted.

object.put() fails with an HTTP 400 "Bad Request"

It looks like you're using an API client library. Please note that any issues related to a specific API client (e.g. pynetbox) must be raised against the client library and not NetBox itself.

the fact that "description" and "dns_name" are listed as being "not null"

This means the column cannot be null. It does not mean they cannot be empty strings. Please don't make assumptions about the API based on the database schema.

@jeremystretch commented on GitHub (Oct 7, 2020): The NetBox REST API _does_ inform you when required fields are absent, but this can only happen if it understands the request to begin with. For example, if I try to create an IP address without specifying its `address`, the error message is quite clear. ``` $ curl -X POST \ > -H "Authorization: Token $TOKEN" \ > -H "Content-Type: application/json" \ > -H "Accept: application/json; indent=4" \ > http://localhost:8000/api/ipam/ip-addresses/ \ > --data '{"description": "foo"}' { "address": [ "This field is required." ] } ``` If you're not seeing these validation errors, it's because NetBox doesn't understand the request to begin with. This is likely because the request data is encoded wrong or badly formatted. > object.put() fails with an HTTP 400 "Bad Request" It looks like you're using an API client library. Please note that any issues related to a specific API client (e.g. pynetbox) must be raised against the client library and not NetBox itself. > the fact that "description" and "dns_name" are listed as being "not null" This means the column cannot be null. It does _not_ mean they cannot be empty strings. Please don't make assumptions about the API based on the database schema.
Author
Owner

@jogulin commented on GitHub (Oct 7, 2020):

So the log file will put this in it at both INFO and DEBUG levels:

Bad Request: /api/ipam/ip-address/1/

I would expect the log to show this too.

@jogulin commented on GitHub (Oct 7, 2020): So the log file will put this in it at both INFO and DEBUG levels: Bad Request: /api/ipam/ip-address/1/ I would expect the log to show this too.
Author
Owner

@jogulin commented on GitHub (Oct 8, 2020):

When I dig further, yes there is probably an issue with the API module but when I look at the response it says that the assigned_object_id cannot be null... but the assigned_object_type and assigned_object fields are both also "None" (python)... which means somewhere in there in spite of the assigned_object_id and assigned_object both being None there is something that is altering that fact.

@jogulin commented on GitHub (Oct 8, 2020): When I dig further, yes there is probably an issue with the API module but when I look at the response it says that the assigned_object_id cannot be null... but the assigned_object_type and assigned_object fields are both also "None" (python)... which means somewhere in there in spite of the assigned_object_id and assigned_object both being None there is something that is altering that fact.
Author
Owner

@jeremystretch commented on GitHub (Oct 8, 2020):

I'm going to close this issue as there doesn't appear to be anything actionable. Please post to our mailing list if you require further assistance using the REST API.

@jeremystretch commented on GitHub (Oct 8, 2020): I'm going to close this issue as there doesn't appear to be anything actionable. Please post to our [mailing list](https://groups.google.com/g/netbox-discuss) if you require further assistance using the REST API.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4170