Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or EOI

SOLVED
Go to solution
New Contributor

Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or EOI

Hi,

I'am facing issues while using the new metadata search api:

https://api.box.com/2.0/metadata_queries/execute_read

 

while setting the "from" parameter to look for the securityClassification template, im getting this error:

{
    "message""Failed to parse query: Invalid input '-', expected simpleIdentifierTail or EOI (line 1, pos 42):\nenterprise_id.securityClassification-6VMVochwUWo\n                                         ^\n",
    "code""invalid_query",
    "request_id""ip14lmgfmz4jkw40"
}
 

Here's the full request body

{
"ancestor_folder_id":"value",
"from": "enterprise_ID.securityClassification-6VMVochwUWo",
"query": "Box__Security__Classification__Key = :template",
"query_params": {
"template": "Confidential"
}
}

 

Seems like the API doesn't allow '-' in the "from" parameter but in this case this is a valid template name.

Tags (1)
4 REPLIES 4
Highlighted
Box Employee

Re: Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or

Hi @Eric121 

 

I'll preface this by saying that Box doesn't currently support querying classifications because it is very likely that you will eventually bump into either:

1. The limit on the number of metadata instances (which is 10,000 - above which we require an index for any query referencing that template)

2. The limit on the number of results your query matches prior to evaluation of user permissions or the location in your folder structure (which is 2,000 - above which we may fail a query an indicate it needs to be more selective). 

 

You can review details about these limits here: https://developer.box.com/guides/metadata/queries/limitations/

 

Now to the specific issue which is actually related to escaping certain characters. If your templateKey or field key contains a special character (not alphanumeric or underscore), you must quote the string with double quotes and use a backslash to escape these double quotes.

 

In your example, the classification template contains a hypen, which needs to be escaped. The following is the appropriate syntax to do so:

 

{
"from": "enterprise_myEID.\"securityClassification-someString\"",
...
}

As another example, imagine you have a field key with a hyphen, such as a field called vendor-name. The resulting query to reference this field would look as follows:

 

"query": "\"vendor-name\" = :name"

 

Can you share a bit more about what you're trying to do with Classifications and the Query API? There may be an alternative to accomplish your goal. If you don't feel comfortable sharing in 

Tags (2)
Highlighted
New Contributor

Re: Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or

Hi @dandennhardt ,

Thanks for the solution.

I'm trying to query all the items under a folder which have classification 'A' or 'B' or 'C' etc.....

I'm currently using the search API but it doesn't support logical operators in filters so have to make call for fetching the result for each classification separately.

So i'm trying to use this api now to optimise the number of calls.

Highlighted
Box Employee

Re: Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or

Okay, great. Thanks for the feedback @Eric121. Are the items all direct children of the parent folder, for example:

Folder
-File
-File

Or are the items at different levels, for example

Folder
-File
-Folder
--File

 

Highlighted
New Contributor

Re: Metadata Search API: Failed to parse query: Invalid input '-', expected simpleIdentifierTail or

@dandennhardt 

The items can be at any level