httpAction
can't seem to get the body inside an http post action
https://docs.convex.dev/functions/http-actions
body is undefined everytime?
TS
import { httpAction } from "./_generated/server";
import { internal } from "./_generated/api";
export const postMessage = httpAction(async (ctx, request) => {
const { author, body } = await request.json();
await ctx.runMutation(internal.messages.sendOne, {
body:
Sent via HTTP action: ${body}
,
author,
});
return new Response(null, {
status: 200,
});
});HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I'm guessing you're testing this in the Dev deployment?
Can you share an example of how you're calling the HTTP endpoint?
await request.json();
is the body
so don't unpack it, and print what the result of const data = await request.json()
is with console.log(data)
well it's the message body
so you'll be able to see what payload was sent inthank you
The problem I see is that the code snippet @burnstony#1975 shared is directly from the docs, where it shows unpacking both
author
and body
from the request.ah maybe we should rename that variable to "message" or something; it makes sense in the docs but that code sample out of context you could think that will be the request body