#httpAction

10 messages · Page 1 of 1 (latest)

cosmic pollen
#

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 allow you to build an HTTP API right in Convex!

wind compassBOT
#

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](https://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!
ionic quarry
#

I'm guessing you're testing this in the Dev deployment?

#

Can you share an example of how you're calling the HTTP endpoint?

keen sage
#

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 in

cosmic pollen
#

thank you

ionic quarry