I have a next js 13, typescript and Prisma, project and I am trying to implement the create a zoom call Api in my code:
I do successfully get a meeting, but the time is wrong. So, I choose Say May 28th at 10am and I get May 28th at 4am. I can’t figure out why.
My Server Code:
import { NextRequest, NextResponse } from “next/server”;
import prisma from “@/lib/prisma”;
import { scheduleZoomMeeting } from “@/lib/zoom”;
import { formatInTimeZone, toDate } from “date-fns-tz”;
import { parseISO, format } from “date-fns”;
export async function POST(request: NextRequest) {
try {
const {
name,
email,
businessName,
phoneNumber,
country,
callTime,
callDate,
timeZone,
notes,
contactAgreement,
} = await request.json();
console.log("Received values:", {
name,
email,
businessName,
phoneNumber,
country,
callTime,
callDate,
timeZone,
notes,
contactAgreement,
});
// Combine date and time into a single string
const dateTimeStr = `${callDate}T${callTime}`;
console.log("Combined dateTimeStr:", dateTimeStr);
// Parse the date and time string using date-fns
const parsedDate = parseISO(dateTimeStr);
console.log("Parsed date:", parsedDate);
if (isNaN(parsedDate.getTime())) {
throw new Error("Invalid date or time value");
}
// Convert the parsed date to the desired time zone
const zonedDate = toDate(parsedDate, { timeZone });
console.log("Zoned date:", zonedDate);
// Format the date in UTC
const formattedDate = formatInTimeZone(
zonedDate,
"UTC",
"yyyy-MM-dd'T'HH:mm:ssXXX"
);
console.log("Formatted date:", formattedDate);
// Create a Zoom meeting using the access token
const zoomMeeting = await scheduleZoomMeeting({
topic: `Meeting with ${name}`,
start_time: formattedDate,
duration: 30,
});
// Ensure zoom_meeting_id is treated as a string
const zoomMeetingId = String(zoomMeeting.id);
// Create a new schedule in the database with Zoom meeting details
const newSchedule = await prisma.scheduleCall.create({
data: {
name,
email,
business_name: businessName,
phone_number: phoneNumber,
country,
call_time: callTime,
call_date: callDate,
time_zone: timeZone,
notes,
contact_agreement: contactAgreement,
zoom_meeting_id: zoomMeetingId,
zoom_meeting_join_url: zoomMeeting.join_url,
zoom_meeting_start_url: zoomMeeting.start_url,
},
});
return NextResponse.json(newSchedule, { status: 200 });
} catch (error) {
console.error(“Error scheduling call:”, error);
if (error instanceof Error) {
return NextResponse.json(
{ error: “Failed to schedule call”, details: error.message },
{ status: 500 }
);
} else {
return NextResponse.json(
{
error: “Failed to schedule call”,
details: “An unknown error occurred”,
},
{ status: 500 }
);
}
}
}
some logs: form the code:
Received values: {
name: ‘dewfa’,
email: ‘davidfales@codecrafty.dev’,
businessName: ‘Code Crafty LLC’,
phoneNumber: ‘7206122979’,
country: ‘United States’,
callTime: ‘10:00:00’,
callDate: ‘2024-05-28’,
timeZone: ‘America/Denver’,
notes: ‘deqwdd’,
contactAgreement: true
}
Combined dateTimeStr: 2024-05-28T10:00:00
Parsed date: 2024-05-28T10:00:00.000Z
Zoned date: 2024-05-28T10:00:00.000Z
Formatted date: 2024-05-28T10:00:00Z
Scheduling Zoom meeting with details: {
topic: ‘Meeting with dewfa’,
start_time: ‘2024-05-28T10:00:00Z’,
duration: 30
}
Zoom meeting scheduled successfully: {
uuid: ‘WJleG7dcTmmlN8UaTjxWdA==’,
id: 82875979312,
host_id: ‘pB3H0HTvRwiagoYWfa1YXg’,
host_email: ‘admin@codecrafty.dev’,
topic: ‘Meeting with dewfa’,
type: 2,
status: ‘waiting’,
start_time: ‘2024-05-28T10:00:00Z’,
duration: 30,
timezone: ‘America/Denver’,
created_at: ‘2024-05-26T03:19:41Z’,
start_url: zak=eyJ0eXAiOiJKV1QiLCJzdiI6IjAwMDAwMSIsInptX3NrbSI6InptX28ybSIsImFsZyI6IkhTMjU2In0.eyJhdWQiOiJjbGllbnRzbSIsInVpZCI6InBCM0gwSFR2UndpYWdvWVdmYTFZWGciLCJpc3MiOiJ3ZWIiLCJzayI6IjAiLCJzdHkiOjEsIndjZCI6InVzMDUiLCJjbHQiOjAsIm1udW0iOiI4Mjg3NTk3OTMxMiIsImV4cCI6MTcxNjcwMDc4MSwiaWF0IjoxNzE2NjkzNTgxLCJhaWQiOiJEQk9LQXhPZlJKaW5mVUR1LUk3ZkNBIiwiY2lkIjoiIn0.RX9LL0gFgiCxs-2TMGHt74zG1EKckSmJTQqyxxM-GvI’,
join_url:
pwd=62bn8ivdG1kdcYQxkrfLx5bV9VoB7y.1’,
password: ‘NbHW6x’,
h323_password: ‘918112’,
pstn_password: ‘918112’,
encrypted_password: ‘62bn8ivdG1kdcYQxkrfLx5bV9VoB7y.1’,
settings: {
host_video: false,
participant_video: false,
cn_meeting: false,
in_meeting: false,
join_before_host: true,
jbh_time: 0,
mute_upon_entry: false,
watermark: false,
use_pmi: false,
approval_type: 2,
audio: ‘voip’,
auto_recording: ‘none’,
enforce_login: false,
enforce_login_domains: ‘’,
alternative_hosts: ‘’,
alternative_host_update_polls: false,
close_registration: false,
show_share_button: false,
allow_multiple_devices: false,
registrants_confirmation_email: true,
waiting_room: false,
request_permission_to_unmute_participants: false,
registrants_email_notification: true,
meeting_authentication: false,
encryption_type: ‘enhanced_encryption’,
approved_or_denied_countries_or_regions: { enable: false },
breakout_room: { enable: false },
internal_meeting: false,
continuous_meeting_chat: { enable: false, auto_add_invited_external_users: false },
participant_focused_meeting: false,
push_change_to_calendar: false,
resources: ,
auto_start_meeting_summary: false,
alternative_hosts_email_notification: true,
show_join_info: false,
device_testing: false,
focus_mode: false,
meeting_invitees: ,
enable_dedicated_group_chat: false,
private_meeting: false,
email_notification: true,
host_save_video_order: false,
sign_language_interpretation: { enable: false },
email_in_attendee_report: false
},
pre_schedule: false
}
Any help would be nice. I’ve seen in some places its a time zone thing that its auto UTC but I tried to fix that and I couldn’t.