Skip to main content
Question

Search with metadata: teamplateA.field=X or templateB.field=X

  • May 22, 2025
  • 1 reply
  • 5 views

Forum|alt.badge.img

I'm looking for a way to do a search based on different templates, something like: templateA.field = AAA or templateB.field = AAA

Could someone give me a hint of is it possible at all?

 

My code below:

{code}

const BoxSDK = require('box-node-sdk');
const sdkConfig = require('./config.json');

(async () => {
var sdk = BoxSDK.getPreconfiguredInstance(sdkConfig);
var client = sdk.getAppAuthClient('enterprise');
client.asUser('XXXXX');

const filterA = {
templateKey: 'templateA',
scope: 'enterprise_XXXX',
filters: { psPartNo: '11111' }
};

const filterB = {
templateKey: 'templateB',
scope: 'enterprise_XXXX',
filters: { psPartNo: '11111' }
};

 

await client.search.query('', {
ancestor_folder_ids: '0',
fields: 'name',
mdfilters: [ filterA ]
})
.then(r => console.log('Result has', r.total_count, 'items:', r.entries.map(x => x.name).join(', ')))
.catch(e => console.log(e.message));

// Result has 1 items: ....

 

await client.search.query('', {
ancestor_folder_ids: '0',
fields: 'name',
mdfilters: [ filterB ]
})
.then(r => console.log('Result has', r.total_count, 'items:', r.entries.map(x => x.name).join(', ')))
.catch(e => console.log(e.message));

// Result has 2 items: ....

 

 

// *************

// Here i'm looking of how to:

// 1) use multiple templates

// 2) use OR condition

await client.search.query('', {
ancestor_folder_ids: '0',
fields: 'name',
mdfilters: [ filterA, filterB ]
})
.then(r => console.log('Result has', r.total_count, 'items:', r.entries.map(x => x.name).join(', ')))
.catch(e => console.log(e.message));
})();

// Unexpected API Response [400 Bad Request | **** ] bad_request - Bad Request

{code}

1 reply

Forum|alt.badge.img

Hi Anton

Currently you can only search against a single metadata template in Box search and metadata query API. 

You can upvote and add your comments/use case to this pulse request which asks for the functionality you need.

https://pulse.box.com/forums/909778-help-shape-the-future-of-box/suggestions/36107128-search-metadata-attributes-across-multiple-metadata

Best regards

Peter Christensen, Platform Solutions Engineer, Box