I want to make the id
path optional.
The webhook should accept /user/
and also /user/1cba67da-b5a0-4cfb-88b3-cbf4ef6adc38
, for example.
I’ve tried using :id?
and (?:/:id)?
but neither worked.
Information on your n8n setup
- n8n version: 1.73.1
- Database (default: SQLite): default
- n8n EXECUTIONS_PROCESS setting (default: own, main): default
- Running n8n via (Docker, npm, n8n cloud, desktop app): docker
- Operating system: Ubuntu 24.04
Hey @gmsalomao2 , could you us ID in the querystring instead?
You mean like /user/id=
?
Yeah, I could. I could even pass it in the body.
But I’m really trying to follow REST API guidelines.
For now I created two POST webhooks. One for /user/
and another for /user/:id
But it would be some much simpler if I could add optional paths. Once the API gets more complex I’ll end up with paths like this:
/content/comment/:id
And it would be great if I didn’t have to create one webhook for each new path, but add optional paths instead.
@ihortom
To be precise, it is like this, /user/?id=
.
I doubt it could be done as the endpoint has to be registered, and the workflows allows for only one trigger of the same kind. Having both /user
and /user/id
implies two endpoints registered with the same workflow.
1 Like
Oh yeah. Forgot the ?
.
Weirdly enough I was able to have both /user
and user/:id
enabled at the same time. Both listening for POST requests.
But it’ll probably become a problem in a near future, since I’d have to create many duplicates of that kind.
It looks like I’ll have to deviate from the recommend REST API practices
Interesting. Yes, apparently I was allowed to have two webhooks in the single workflow to achieve what you are after. Judging by that you still can adhere to REST API practice with n8n, you just need to have more than one webhook in the workflow.
In that case you might want to raise a Feature request so that you could do it with a single Webhook node.
Yeah, but that would make things messy.
Ended up using a “path” query parameter for the endpoint.
And one webhook for each request method, like this:
Then I send each endpoint to the respective subworkflow.
There I split each “subpath” into it’s own actions.
For example:
DELETE https://webhook.com/?path="/user/235235-45sdf/profile-pic"
path = /user/235235-45sdf/profile-pic
- Would go to USER subworkflow
- In the subworkflow it would go to the PROFILE PIC path
- And then to the DELETE path