box / box-node-sdk

A Javascript interface for interacting with the Box API. You can find the node package at
https://www.npmjs.com/package/box-node-sdk
Apache License 2.0
187 stars 121 forks source link

Query by metadata has incorrect options #877

Closed swanysimon closed 4 months ago

swanysimon commented 4 months ago

Description of the Issue

The query by metadata function is not correct and will always result in a 400 Bad Request if query_parameters are supplied. Specifically, the query_parameters options should be query_params, and order_by should be optional. In addition there are missing options: limit and marker.

API Reference: https://developer.box.com/reference/post-metadata-queries-execute-read/

Steps to Reproduce

An example:

    const options = {
      fields: ["id", "name", "sha1"],
      query: "myMetadataIdField = :id",
      query_parameters: {id: "my_special_id"},
      order_by: {},
    };
    return this.client.metadata.query(
      "enterprise_scope.metadataTemplateKey",
     "123",
      options,
    );

And you receive a:

Error: Unexpected API Response [400 Bad Request | ...] invalid_query - Parameter id: no value provided

(I actually got this error after removing the order_by field because before that, you don't even get a reason for why the request was bad, you just get a 400)

Expected Behavior

To receive a 200 response and my matching files.

Workaround

Forcibly ignore the type mismatch.

    const options = {
      fields: ["id", "name", "sha1"],
      query: "myMetadataIdField = :id",
      query_params: {id: "my_special_id"},
    };
    return this.client.metadata.query(
      "enterprise_scope.metadataTemplateKey",
     "123",
      // @ts-expect-error: option type definition for metadata query is incorrect
      options,
    );

Error Message, Including Stack Trace

I'd rather not redact, and this seems pretty straightforward.

Screenshots

n/a

Versions Used

Node SDK: 3.1.1 and 3.5.0

arjankowski commented 4 months ago

Hi @swanysimon, We've just released the new version of box-node-sdk, 3.5.1, with the fix to the bug you mentioned.

Regards, Artur