calcom/cal.com

V1 Slots API Returning Slots outside of requested range

Opened this issue ยท 0 comments

Found a bug? Please fill out the sections below. ๐Ÿ‘

Issue Summary

When requesting slots via v1/slots API between a startTime and EndTime, where the event has no availability (i.e. 9/24), I expect to to get an empty slots map. Instead I am getting back slots for a previous day.

Screenshot of availability:
image

Steps to Reproduce

Paste this in a file called index.js and run via node index.js:

async function fetchAvailability(startTime, endTime) {
    const apiKey = process.env.CAL_API_KEY;

    const url = new URL(`https://api.cal.com/v1/slots`);
    url.searchParams.append("startTime", startTime)
    url.searchParams.append("endTime", endTime)
    url.searchParams.append("apiKey", apiKey) // put your own api key here
    url.searchParams.append("usernameList", "govindrai")
    url.searchParams.append("eventTypeSlug", "govind")
    url.searchParams.append("timeZone", "America/Los_Angeles")
    // console.log(url)

    try {
        const response = await fetch(url, {
            headers: {
                'Authorization': `Bearer ${apiKey}`,
                'Content-Type': 'application/json',
            },
            method: "GET",
        });

        if (!response.ok) {
            const error = {
                status: response.status,
                statusText: response.statusText,
                errorResponse: await response.json()
            }
            throw new Error(JSON.stringify(error, null, 2));
        }

        const data = await response.json();
        return data;
    } catch (error) {
        throw error;
    }
}


// Helper function to get the end of a day given a date in ISO format
function getEndOfDayUsingStartTime(date) {
    return new Date(
        date.getFullYear(),
        date.getMonth(),
        date.getDate(),
        23, 59, 59, 999
    ); // Set the time to the end of the day
}

const date = new Date("2024-09-24T00:00:00-07:00")
fetchAvailability(date.toISOString(), getEndOfDayUsingStartTime(date).toISOString())
    .then(console.log)

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

Actual Results

Slots being returned for 9/23 when date range is for 9/24

{
  slots: {
    '2024-09-23': [
      { time: '2024-09-23T10:30:00-07:00' },
      { time: '2024-09-23T14:30:00-07:00' },
      { time: '2024-09-23T14:45:00-07:00' },
      { time: '2024-09-23T15:00:00-07:00' },
      { time: '2024-09-23T15:15:00-07:00' },
      { time: '2024-09-23T15:30:00-07:00' },
      { time: '2024-09-23T15:45:00-07:00' },
      { time: '2024-09-23T16:00:00-07:00' },
      { time: '2024-09-23T16:15:00-07:00' },
      { time: '2024-09-23T16:30:00-07:00' }
    ]
  }
}

When I changing the date to 2024-09-26T00:00:00-07:00, I get availability for 9/23 and 9/25

{
  slots: {
    '2024-09-23': [
      { time: '2024-09-23T10:30:00-07:00' },
      { time: '2024-09-23T14:30:00-07:00' },
      { time: '2024-09-23T14:45:00-07:00' },
      { time: '2024-09-23T15:00:00-07:00' },
      { time: '2024-09-23T15:15:00-07:00' },
      { time: '2024-09-23T15:30:00-07:00' },
      { time: '2024-09-23T15:45:00-07:00' },
      { time: '2024-09-23T16:00:00-07:00' },
      { time: '2024-09-23T16:15:00-07:00' },
      { time: '2024-09-23T16:30:00-07:00' }
    ],
    '2024-09-25': [
      { time: '2024-09-25T11:00:00-07:00' },
      { time: '2024-09-25T11:15:00-07:00' },
      { time: '2024-09-25T11:30:00-07:00' }
    ]
  }
}

What my URL object looks like:

URL {
  href: 'https://api.cal.com/v1/slots?startTime=2024-09-26T07%3A00%3A00.000Z&endTime=2024-09-27T06%3A59%3A59.999Z&apiKey=REDACTED&usernameList=govindrai&eventTypeSlug=govind&timeZone=America%2FLos_Angeles',
  origin: 'https://api.cal.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'api.cal.com',
  hostname: 'api.cal.com',
  port: '',
  pathname: '/v1/slots',
  search: '?startTime=2024-09-26T07%3A00%3A00.000Z&endTime=2024-09-27T06%3A59%3A59.999Z&apiKey=REDACTED&usernameList=govindrai&eventTypeSlug=govind&timeZone=America%2FLos_Angeles',
  searchParams: URLSearchParams {
    'startTime' => '2024-09-26T07:00:00.000Z',
    'endTime' => '2024-09-27T06:59:59.999Z',
    'apiKey' => 'REDACTED',
    'usernameList' => 'govindrai',
    'eventTypeSlug' => 'govind',
    'timeZone' => 'America/Los_Angeles' },
  hash: ''
}

Expected Results

{
  slots: {
    '2024-09-24': []
  }
}

Technical details

  • Node.js version: v21.5.0