Hello together, I’m building a Notion integration in n8n and trying to filter tasks based on dynamic inputs. I have a “Search inside Task DB” HTTP node that should filter tasks by customer_id, project_id, or both – depending on the input.
Current Workflow:
In my setup, these values are dynamically retrieved from prior nodes (Get Customer Page ID and Get Project Page ID). However, I cannot guarantee that both values are always present. Sometimes only the customer or only the project is provided.
If both values are present, the filter works correctly and returns the expected results.
But if one value (e.g., project_id) is missing or empty, the filter still includes it – and the request fails with a 400 error. I want to dynamically omit missing filters and let the query run with only the available ones.
What is the error message (if any)?
HTTP 400 – Bad request: please check your parameters
I’m using a Function node to construct the dynamic body like this (but the dynamic body doesn’t work yet):
const andConditions = ;
if ($json.customer_id) {
andConditions.push({
property: “Verknüpfung zu Kunden”,
relation: {
contains: $json.customer_id
}
});
}
if ($json.project_id) {
andConditions.push({
property: “Verknüpfung zu Projekt”,
relation: {
contains: $json.project_id
}
});
}
return [{
filter: {
and: andConditions
}
}];
The only body that is working for me right now is this (with placeholders):
{
“filter”: {
“and”: [
{
“property”: “Verknüpfung zu Kunden”,
“relation”: {
“contains”: “{customer_id}”
}
},
{
“property”: “Verknüpfung zu Projekt”,
“relation”: {
“contains”: “{project_id}”
}
}
]
}
}
The http request for search inside the task database:
But here I only can use it when both values are provided.
If both IDs are present, the response is correct and filtered.
If either customer_id or project_id is missing (empty string or undefined), the request fails with HTTP 400 because I used placeholders.
What I want
I want this filter logic to be robust and flexible:
If both IDs are present → filter by both
If only one is present → filter by that one
If neither is present → return all open tasks
Can you please tell me what I should change to get dynamic bodies?
Thank you very much!







