Next.js Discord

Discord Forum

Trying to call other endpoints in my route

Unanswered
American Sable posted this in #help-forum
Open in Discord
American SableOP
I'm trying to call another endpoint async in my main one.
Basically want to return 200 on the main after he triggers the other ones.
This works perfectly in my local machine but when I deploy it in Vercel the other endpoint wont trigger.
Thanks.
        const conversation = await prisma.conversation.findFirst({
          where: {
            senderId: message.senderId,
          },
        });
        console.log(
          `${process.env.BASE_URL}/api/whatsapp/services/preValidation`
        );

        if (!conversation?.verify || !conversation) {
          console.log("member is not verified yet");
          axios.post(
            `${process.env.BASE_URL}/api/whatsapp/services/preValidation`,
            {
              conversation: conversation,
              message: message,
              recipientId: teamId,
              source: "whatsapp",
            }
          );
          return new Response("message is not verified yet", {
            status: 200,
          });
        }

        axios.post(
          `${process.env.BASE_URL}/api/facebook/services/handleMessages`,
          {
            conversation: conversation,
            message: message,
            recipientId: teamId,
          }
        );
return new Response("EVENT_RECEIVED", { status: 200 });

2 Replies

One strategy I've used in the past is to move the content of my API routes into a function, that way I can call that function from your API route and from this function here are both calling the same code. Hope that helps!
American SableOP
If im remembering correctly, I moved to this method because when i did not await for my function it just didnt call them, I guess it has to do with how serverless works ( Im not an expert in serverless)