I don't know what is required in the body of those requests. Are there any docs or examples for those?
Didnt find any docs but it seems to just need the fields + new values as stringified json in the body
Can you share an example here?
Hey @alessiogr ! I'm currently not quite understanding how to get a POST request to a custom endpoint working. It seems like you figured it out here potentially?
On the client I tried something like this:
const response = await fetch(`/path/to/custom/endpoint`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(theData),
})
and on the endpoint I have:
const customEndpoint :Endpoint = {
path: '/path/to/custom/endpoint',
method: 'post',
root: true,
handler: async (req, res, next) => {
try {
// How do I get the post body???
res.status(200).send({
message: 'Request successful',
})
}
catch (err) {
console.error(err)
res.status(500).send({
message: 'Error occurred during request',
error: err,
})
}
},
}
export default customEndpoint
Still haven't figured out how to get the post body
Looks like in my case I'm attempting to post
application/json
where in payload it only accepts
application/x-www-form-urlencoded
?
hm.. tried a test
application/x-www-form-urlencoded
post and
req.body
is still undefined
feels like the typical bodyParser middleware isn't firing for custom endpoints. Perhaps this is actually different from the original post
I made another post in case someone else runs into this :
https://discordapp.com/channels/967097582721572934/1111352788253941862
Turns out it had to do with setting
root
to
true
in the handler
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.