Skip to main content

Hello,


I am experiencing an issue with the NodeSDK, whenever I apply any data shape, to boxClient.folders.addMetadata() it throws a 400 with “message”: “Request contains invalid parameters.”, If I apply a empty object {}, it works without issue. (So I know that i am able to connect, and have permissions ect)



The shape of the metadata template is:


image



The relevant code:


const metadataValues = {


ENTITY_ID: “1234”,


is_Active: “1”,


is_Found: “1”,


};


let response_metadata_applied = await this.boxClient.folders.addMetadata(folder_id, “enterprise_534608”, “ciptemplate”, metadataValues);



It throws a 400, with that error.


If I apply


let response_metadata_applied = await this.boxClient.folders.addMetadata(folder_id, “enterprise_534608”, “ciptemplate”, {});


It works 100%, but the values are of course empty.



I have tried all methods of controlling the body: when I look at the error response


{


“statusCode”: 400,


“response”: {


“statusCode”: 400,


“body”: {


“message”: “Request contains invalid parameters.”,


“code”: “bad_request”,


“request_id”: “ic7oqbhkrlg85i9k”


},


…(bunch of stuff)


“body”: “{"ENTITY_ID":"1234","is_Active":"1","is_Found":"1"}”


}


When I toss that body thru a JSON.parse it comes out ok.?!



Is there something obvious I am missing? My code is almost identitical the code used on the example page: https://developer.box.com/reference/post-folders-id-metadata-id-id/



What am I missing, I know its related to the body the metadataValues I am passing? What’s the secret sauce I am missing.



Thank you,


Andrew

I found the answer to this, and I think it should be shared publicly as its not declared anywhere in the documenation.



When you create a template, and you enter its name, apparently in the background they change the key.


So when I entered Entity_ID and is_Active, behind the scenes that was changed into entityid, isactive and isfound.



I found this out by boxClient.metadata.getTemplateSchema(‘enterprise’, ‘ciptemplate’);


Which returned:


{


…bunch of stuff


“fields”:


{


“id”: “31363717-b4ac-4f21-a1c7-622b1f8d1e91”,


“type”: “string”,


“key”: “entityid”,


“displayName”: “ENTITY_ID”,


“hidden”: false,


“description”: “…”


},


}


as you can see, the key is the Displayname stripped of -, _ and whatever. Box, please note this somewhere in the template documentation on the POST section. Or link to https://developer.box.com/guides/metadata/templates/get/


and point out created names of key,value pairs may not be what you entered when you made the template.



Hope this helps somebody else in the future.



Andrew


Hi @AndrewC , welcome to the forum.



You’re right, it is not explicitly called out in the documentation, and neither on the articles.



I’ll ping the docs team.



Speaking of articles, did you find our series of articles around metadata? If so were they useful?





Cheers


I find your documentation normally top shelf! 🙂



I mean its normally so spot on, it lead me to believe for sure I was the problem! LOL



As for the Metadata stuff, yes, its detailed and with this one exception following/using it, my product is moving along nicely. All for all, congrats on a solid SDK!


Reply