Next.js Discord

Discord Forum

TypeError: The "payload" argument must be of type object. Received null at POST

Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Open in Discord
Cuvier’s Dwarf CaimanOP
Hello guys, I'm trying to POST to my database with Prisma, but I obtain this error, here are my following files:

route.ts:
export async function POST(req: Request) {
  try {
    const body = await req.json();

    if (!body.usuarioId || !body.usuarioNombre || !body.tiendaId || !body.valoracionTexto) {
      return new NextResponse(
        JSON.stringify({ error: 'Faltan campos requeridos' }),
        { status: 400 }
      );
    }

    const nuevaValoracion = await prisma.valoracion.create({
      data: {
        usuarioId: body.usuarioId,  
        usuarioNombre: body.usuarioNombre,  
        tiendaId: body.tiendaId,  
        atCliente: body.atCliente || null,  
        valoracionTexto: body.valoracionTexto || null,  
        verificado: body.verificado || false,  
        envios: body.envios || null,  
        precios: body.precios || null,  
      },
    });

    return new NextResponse(
      JSON.stringify({ message: 'Valoración guardada correctamente', nuevaValoracion }),
      { status: 200 }
    );
  } catch (error) {
    console.error("Error al guardar la valoración:", error);
    return new NextResponse(
      JSON.stringify({ error: "Error al guardar la valoración" }),
      { status: 500 }
    );
  }
}


ReviewForm.js:

4 Replies

Cuvier’s Dwarf CaimanOP
I don't know what's wrong
It's my first time with prisma and next and this is causing me some trouble :S
Spectacled bear
Can you post the erorr as well?
Can you confirm if body is being sent in the browser network tab?