Welcome to the new Box Support website. Check out all the details here on what’s changed.

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

Answered
New post

Comments

5 comments

  • dandennhardt

    Hi  

     

    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 

    0
    Comment actions Permalink
  • Eric121

    Hi  ,

    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.

    0
    Comment actions Permalink
  • dandennhardt

    Okay, great. Thanks for the feedback . 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

     

    0
    Comment actions Permalink
  • Eric121

     

    The items can be at any level

    0
    Comment actions Permalink
  • macgirlsweden

    I am facing a similar challenge.

    I want to search for a custom metadata field in this case "issueType" and get a listing for all documents. The use case is to handle file belonging to a certain case while allowing users to organise them i subfolders.

    I am using this endpoint:

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

    {
    "from": "enterprise_3727xxxxx.contentperspectivemvp0",
    "query": "issueType = :issueType",
    "query_params": {
    "issueType": "\"Racial Injustice\""
    },
    "fields": [
    "created_at",
    "metadata.enterprise_3727xxxxx.contentperspectivemvp0.issueType",
    "metadata.enterprise_3727xxxxx.contentperspectivemvp0.movementType"
    ],
    "ancestor_folder_id": "121493081635",
    "order_by": [
    {
    "field_key": "created_at",
    "direction": "asc"
    }
    ],
    "limit": 50,
    }
     
    I am getting errors like this when running it through Postman with a developer token:
     
    {
    "type": "error",
    "status": 400,
    "code": "bad_request",
    "context_info": {
    "errors": [
    {
    "reason": "invalid_parameter",
    "name": "entity-body",
    "message": "Invalid value '{\n \"from\": \"enterprise_3727xxxxx.contentperspectivemvp0\",\n \"query\": \"issueType = :issueType\",\n \"query_params\": {\n \"issueType\": \"\\\"Racial Injustice\\\"\"\n },\n \"fields\": [\n \"created_at\",\n \"metadata.enterprise_3727xxxxx.contentperspectivemvp0.issueType\",\n \"metadata.enterprise_3727xxxxx.contentperspectivemvp0.movementType\"\n ],\n \"ancestor_folder_id\": \"121493081635\",\n \"order_by\": [\n {\n \"field_key\": \"created_at\",\n \"direction\": \"asc\"\n }\n ],\n \"limit\": 50,\n}'. Entity body should be a correctly nested resource attribute name/value pair"
    }
    ]
    },
    "message": "Bad Request",
    "request_id": "43wjdbgijvw41yd2"
    }
     
    Anyone know what to do?
    1
    Comment actions Permalink

Please sign in to leave a comment.