Using nylas with next js

I’m new to nylon just started using it today, I was try to integrate it to my old next js app router project follow the setup of using nodejs i almost get it but seeing this error.

  type: 'provider_error',
  requestId: 'a01984eb-21d4-4fe2-ae55-5b03a37130a1',
  providerError: {
    error: { code: 400, message: 'The specified time range is empty.' }
  },
  statusCode: 400
}

This my code for create-event:

`


export async function POST(request: Request) {
  const { accessToken, startTime, endTime, title, description, email } =
    await request.json();

  // if (!accessToken || !startTime || !endTime || !title) {
  //   return NextResponse.json(
  //     { error: "Missing required fields" },
  //     { status: 400 },
  //   );
  // }

  try {
    const event = await ns.events.create({
      identifier: process.env.NYLAS_GRANT_ID as string,
      requestBody: {
        calendarId: "primary",
        title,
        description,
        when: { startTime, endTime },
        participants: [{
            email: email,
            status: "noreply"
        }],
      },
      queryParams: {
        calendarId: "primary"
      }
    });

    return NextResponse.json({ success: true, event });
  } catch (error) {
    console.error("Error creating event:", error);
    return NextResponse.json(
      { error: "Failed to create event" },
      { status: 500 },
    );
  }
}

`

how am using it
const handleBooking = async () => { if (currentUser) { try { const token = await currentUser.getIdToken(); const response = await axios.post('/api/create-event', { title, description, email, startTime: new Date(startTime).getTime() / 1000, endTime: new Date(endTime).getTime() / 1000, }, { headers: { token }, }); console.log('Event created:', response.data); } catch (error) { console.error('Error creating event:', error); } } };

am using firebase as auth. that’s what am using from start of the project.

Hello @devben have you check this code sample? Nylas v3 Email, Calendar, and Contacts API docs | Nylas Docs

Also, make sure you’re passing startTime and endTime in the right format.

That’s definitely code sample am following and Yeah about the startTime format could that be the while it’s not working?


 <input
                  type="datetime-local"
                  value={endTime}
                  onChange={(e) => setEndTime(e.target.value)}/>

This is how am passing the startTime

@ram Could you lend a hand? Javascript is not my strong suit :sweat_smile:

@Blag taking a look :slight_smile:

@devben I am able to use the code sample without issue.

Would logging some of the inputs to nylas.events.create clarify what is being passed in?