Set custom fields to null value (clear the field)
Started by rockolaComet1438 about 1 year ago, 4 replies
-
Show this post
When I try to set a field to an empty string (clear the field) via the Discogs API, it appears to ignore the request and maintains the existing value.
The website provides an interface to do this - for example, the dropdown for the condition fields has a blank line in it that will clear the value if you select it. But if you the list of fields (with option lists for the dropdown fields), [empty] is not one of the options, and ing "value": "" in the JSON when sending the edit-field request returns an error and does not clear the field.
I tried changing the data type to null (ing "value":null instead of "value": ""), but it had no effect.
Here is the error I'm getting from the API:
{
"detail" :
[
{
"loc" : [ "body", "value" ],
"msg" : "none is not an allowed value",
"type" : "type_error.none.not_allowed"
}
],
"message" : "See \"detail\" for validation errors.",
} -
rockolaComet1438 edited about 1 year ago
I thought that maybe since each field is an "instance" and doesn't exist under the "notes" array in the release JSON until it has been set to something, that the solution (even though it is not published in the API documentation) is to use the "DELETE" request type to delete the field instance, like you can with Folders or Collection Instances. Unfortunately, this does not work. Here is the response I received:
{"message":"Method Not Allowed"}
On the website, I used the blank line in the dropdown to remove a condition value from a release (note: this only works in the Collection List View, not in the In Collection box on the Release page), and then retrieved the release from the API, and it shows the empty string for "value". But when I send that same value to the field via the API, it is considered an invalid value.
// retrieving release that has never had condition fields set
"notes" :
[
{
"field_id" : 4,
"value" : "30.6"
}
],
// retrieving fields on a release with condition fields set
"notes" :
[
{
"field_id" : 1,
"value" : "Very Good Plus (VG+)"
},
{
"field_id" : 2,
"value" : "Very Good Plus (VG+)"
},
{
"field_id" : 4,
"value" : "30.6"
}
],
// retrieving after clearing condition fields in browser (this is what I want to do via the API, but can't)
"notes" :
[
{
"field_id" : 1,
"value" : ""
},
{
"field_id" : 2,
"value" : ""
},
{
"field_id" : 4,
"value" : "30.6"
}
], -
Show this post
I'm running into the same issue after trying several of the approaches mentioned above as well. Hopefully Discogs will chime in here and either add for this or document it better in the API docs. -
Show this post
Looks like this has been an issue for 11+ years...
https://www.discogs.sie.com/forum/thread/348657?message_id=3276408#3276408 -
Show this post
The only workaround I know of is that this issue only affects custom fields with a value list attached, so if you are willing to forego the value list, you can clear the fields via the API. I'm not willing to do that for the condition fields, though, because then any time I wanted to set a condition field via the web interface, I'd have to free-type the values, e.g. "Very Good Plus (VG+)", each time, and make sure I got them exactly right so that the values would sort/filter accurately.