-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding objects in API with "custom_fields" does not work. #1297
Comments
It looks like this might be an issue with the Swagger UI. When POSTing your example data with curl it works as expected:
Just to confirm, you created the custom field as an integer field, correct? |
No, it was created as a "Selection" field.
…On Wed, Jun 28, 2017 at 11:25 AM, Jeremy Stretch ***@***.***> wrote:
It looks like this might be an issue with the Swagger UI. When POSTing
your example data with curl it works as expected:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <token>" -H "Accept: application/json; indent=4" http://localhost:8000/api/dcim/sites/ -d '{
"name": "Jacksonville-FL",
"slug": "jax",
"region": "1",
"tenant": null,
"facility": "",
"asn": null,
"physical_address": "",
"shipping_address": "",
"contact_name": "",
"contact_phone": "",
"contact_email": "",
"comments": "",
"custom_fields": {
"ce_qos_type": "2"
}
}'
Just to confirm, you created the custom field as an integer field, correct?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1297 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHbDimcibzt_fCbuVCvx-qAPr_ckkd2cks5sIoxsgaJpZM4OFtsc>
.
|
POSTing the following works for me with a selection field:
Note that the value of the field is being passed as an integer. Passing the value as a string yields a validation error ("Invalid choice for field ce_qos_type: 6"). |
I'm trying to get a string value to be stored in the dictionary "ce_qos_type" with one of two values. Either:
I'm going to be using this with Ansible to setup QoS on our border devices, depending on whether the CE can handle Perhaps I'm making this too complicated, if so, I'm open to suggestions. |
Selection fields have pre-defined values to choose from, created under the admin UI. You need to POST the primary key of the desired choice. |
The value of "1" is the primary key for "4_cos" above and the value of "2" is the primary key for "6_cos". This wasn't working in Swagger, and as you stated, it could be an error there, I'm not able to check today. I'm a newbie on APIs, so tomorrow I'll investigate how to get a token in the CLI without using Swagger and report back. Thanks for looking into this so quickly. |
Well, I was able to test it and I CAN get it to work, although I don't understand an error I'm encountering. I created a key for myself and used this on the CLI:
Which resulted in this error coming back:
So, I decided to try without the quotes around the value of Anyways, since I've got this to work, I'm happy to close this issue and I'm very appreciative for you walking me through this, however, I'm still curious about the error. Let me know how you prefer me to proceed. |
Custom fields are a bit odd because we're serializing the value of the field to emulate different data types (e.g. string, integer, or boolean). This inconsistency is likely due to enforcement of the integer type for select fields, if that makes sense. But to your point, NetBox should accept a number-as-a-string for custom fields if other primary key fields do. I'll have to look into it some more. |
…ion PKs as string-quoted integers
Issue type:
Bug
Python version:
2.7.12
NetBox version:
2.0.6
I can use the API to create new sites just fine (via the
Swagger UI
), but when I try to add a new site with a previously definedcustom_field
(via the admin panel in the WebUI), I get the following error:JSON parse error - Extra data: line 18 column 1 - line 18 column 2 (char 343 - 344)"
This works:
This does not work:
The error that I receive is as follows (from
Swagger
):I've used the
GET
function to ensure that thecustom_field
is a correct value. For example:The text was updated successfully, but these errors were encountered: