Search Knowledge base with Question and Filter
Here is the code:
export default async function main(args) {
const { item_number, VFapiKey, brand, question } = args.inputVars;
const url = 'https://general-runtime.voiceflow.com/knowledge-base/query';
const data = {
question: question, // <- must be empty to only filter
chunkLimit: 10,
synthesis: false,
filters: {
brand: {
$eq: brand // <- the exact metadata field from table-upload
}
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'Authorization': VFapiKey
},
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(
HTTP error! status: ${response.status});const responseBody = await response.json;
let chunks = responseBody.chunks "",
first_match_id: chunks[0]?.metadata?.item_number || ""
},
next: { path: "success" }
};
} catch (error) {
return {
outputVars: { error: error.message },
next: { path: "error" }
};
}
}

