cloudinary_npm
cloudinary_npm copied to clipboard
Upload_metadata not working for multiple selection/ single selection metadata fields
Bug report for Cloudinary NPM SDK
Before proceeding, please update to latest version and test if the issue persists
Describe the bug in a sentence or two.
I tried uploading values to a multiple selection field that I had set up in my account. I tried update_metadata, explicit methods. Neither worked for this specific field type, it worked for the string/ number ones. All of the attempts resulted in a 400 error.
Issue Type (Can be multiple)
[ ] Build - Can’t install or import the SDK [ ] Babel - Babel errors or cross browser issues [ ] Performance - Performance issues [x] Behaviour - Functions aren’t working as expected (Such as generate URL) [x] Documentation - Inconsistency between the docs and behaviour [ ] Incorrect Types - For typescript users who are having problems with our d.ts files [ ] Other (Specify)
Steps to reproduce
I tried as specified in documentation:
cloudinary.v2.uploader.update_metadata('countryFieldId=[\"id_us\",\"id_uk\",\"id_france"]', [ 'dog', 'lion' ],
function(error, result) { console.log(result, error) });
=> ERROR:
{
message: `'["id_us","id_uk","id_france"]' is not valid for field 'countryFieldId'`,
name: 'Error',
http_code: 400
}
cloudinary.uploader.update_metadata({ test: "red" }, ["sample"])
.then((res)=> {console.log(res)})
.catch((err)=> {console.log(err)});
=> ERROR:
{
message: "'red' is not valid for field 'test'",
name: 'Error',
http_code: 400
}
I tried sending the metadata in different ways, neither of them worked.
Error screenshots


Browsers (if issue relates to UI, else ignore)
[ ] Chrome [ ] Firefox [ ] Safari [ ] Other (Specify) [ ] All
Versions and Libraries (fill in the version numbers)
Cloudinary_NPM SDK version Node - ^14.9.0 NPM - 6.14.8
Config Files (Please paste the following files if possible)
Package.json
"dependencies": {
"cloudinary": "^1.26.2",
},
Repository
If possible, please provide a link to a reproducible repository that showcases the problem
Hi @andreeadc.
I've tested this on my own account and the metadata was updated successfully. Running
cloudinary.v2.uploader.update_metadata('countryFieldId=[\"id_us\",\"id_uk\",\"id_france"]', [ 'dog', 'lion' ],
function(error, result) { console.log(result, error) });
gave me the response { public_ids: [ 'dog', 'lion' ] } undefined
I first created the metadata field as a set
with
cloudinary.v2.api.add_metadata_field({
"external_id": "countryFieldId",
"type": "set",
"label": "Country Field ID ",
"mandatory": false,
"default_value": null,
"validation": null,
"datasource": {
"values": [
{"external_id": "id_us", "value": "US"},
{"external_id": "id_uk", "value": "UK"},
{"external_id": "id_france", "value": "France"}
]
}
}, function(error, result){
console.log(error, result);
});
Could you please provide us with the output of this code snippet so we can further investigate where things might be going wrong for you?
cloudinary.v2.api.list_metadata_fields(function(error, result){
console.log(error, result);
});
Many thanks, -Danny
Thank you for the quick reply, @dannyv-cloudinary! Ah, I misunderstood what the update_medata is doing. I thought that it will set the values to the metadata fields and will select them aswell. It didn't work in my case because I didn't have the values added in the metadata field's list. That makes sense! I have one more question though: My metadata field is already created inside cloudinary. Is there a way to set the metadata field's values only for specific assets (based on public id)?
Happy to help!
I'm afraid I'm not sure I've fully understood your followup request though. Would you mind providing an example please?
Thanks, -Danny
Sorry for replying this late, I've been OOO. So my use case is: I have an uploaded asset in cloudinary. I have multiple structured metadata fields (including the multiple selection ones, but as a default I don't have any list of options added, I want to add it through the API, for each specific asset). An example would be, I want to have for the multiple selection field "Category", for asset "Asset1", the options: ["Automotive", "Aviation", "Sports" ], but for "Asset2", multiple selection field "Category", would have a different options list, like: ["Fitness", "Swimming"]. As you can see in this example, the same multiple selection field "Category" has different options depending on asset. The way you suggested adding the options list, is setting it for all assets. Is there any way I could do something like that?
Hi @andreeadc, Referring to our Doc example to create a field with different set values: https://cloudinary.com/documentation/metadata_api#examples-1, one field can have multiple datasource values. eg exernal_id: "color1" "value": "red" etc. When you configure the metadata field with one option you can choose one choice from the list values. So you can set the value to be a list in your case: choice 1: ["Automotive", "Aviation", "Sports" ], choice 2: ["Fitness", "Swimming"]
Please let me know if this works. Thanks, Mo
Hi @andreeadc.
We've not heard from you for quite some time now and are unable to reproduce the issue you describe, so I have closed off the issue. If you're still having problems, please let us know and we can take a look for you.
Many thanks, -Danny