cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

[CAL-3756] API Questions - Some endpoints not available / not working

Open pgvr opened this issue 1 year ago • 1 comments

When building autocheckin.app I had to use some tRPC internal endpoints to get the job done or I'm simply blind and overlooked something on https://cal.com/docs/enterprise-features/api/api-reference#the-basics If that's the case, I'm sorry in advance 😅

1. Create Booking Error

Posting to https://api.cal.com/v1/bookings with this body results in this error and I'm not sure what it means. Body

{
  "eventTypeId": 1,
  "start": "2024-04-24T14:30:00.000Z",
  "metadata": {
    "checkin": "true"
  },
  "timeZone": "Europe/Berlin",
  "language": "en",
  "responses": {
    "name": "Patrick",
    "email": "[email protected]",
    "location": ""
  }
}

Error

{
  "message": "custom in 'responses': {notes}error_required_field"
}

The API docs just show these three fields for the responses. I can't reproduce the error for my own eventType, even if my event type requires confirmation.

Edit: When passing "notes" in the "responses" it works, might be worth documenting. It also can't be an empty string, but I think I will be passing something like "Scheduled with autocheckin.app" in there anyways, so not a huge deal.

Also, does the timezone parameter when creating a booking matter? I'm in Germany and tried to pass an American timezone and it still created everything correctly. I'm using times that are returned from the slots endpoint as the start parameter which don't contain a timezone I believe.

2. Unable to cancel booking via API

So the call above works usually and returns an ID for the booking. I would expect that I can then call DELETE https://api.cal.com/v1/bookings/{id}/cancel to cancel the same booking again but I receive this error.

{
  "message": "You are not authorized",
  "error": {
    "name": "HttpError",
    "statusCode": 401
  }
}

The API key is supplied via query params, as usual.

3. Workaround to cancel booking via public API

Since the API call above doesn't work I used this tRPC call to cancel a booking.

  await axios.post("https://app.cal.com/api/cancel", {
    allRemainingBookings: false,
    cancellationReason: "",
    uid,
  });

4. Unable to get eventTypeId for username and eventSlug

For this one I'm probably blind but I didn't find a way to get the ID for an eventType given a username and slug. E.g. given the username bailey and slug chat how can I retrieve the ID (and maybe some other data like owner etc.) from the API?

Right now I'm using this tRPC call do retrieve the info which is not ideal.

  const url = `https://cal.com/api/trpc/public/event?batch=1&input={"0"%3A{"json"%3A{"username"%3A"${username}"%2C"eventSlug"%3A"${eventSlug}"%2C"isTeamEvent"%3Afalse%2C"org"%3Anull}}}`;
  const response = await axios.get(url);

Edit:

5. Title and description seemingly don't do anything when creating a booking

When passing this to the create booking endpoint:

{
  "eventTypeId": 341887,
  "start": "2024-04-24T14:30:00.000Z",
  "metadata": {
    "checkin": "true"
  },
  "timeZone": "Europe/Berlin",
  "title": "Test title",
  "description": "Test description",
  "language": "en",
  "responses": {
    "name": "Patrick",
    "email": "[email protected]",
    "location": "",
    "notes": ""
  }
}

The supplied title and description don't appear anywhere, if I'm not mistaken:

{
  "id": 1838535,
  "uid": "s9ksVFLmNtgiMj2XSsYv3y",
  "idempotencyKey": "cb0893ff-49bf-571b-a685-2de16f3d7117",
  "userId": 99009,
  "userPrimaryEmail": "[email protected]",
  "eventTypeId": 341887,
  "title": "30 Min Meeting between Patrick Göler von Ravensburg and Patrick",
  "description": "",
  "customInputs": {},
  "responses": {
    "name": "Patrick",
    "email": "[email protected]",
    "notes": "",
    "location": {
      "value": "",
      "optionValue": ""
    }
  },
  "startTime": "2024-04-24T14:30:00.000Z",
  "endTime": "2024-04-24T15:00:00.000Z",
  "location": "integrations:daily",
  "createdAt": "2024-04-22T17:24:27.872Z",
  "updatedAt": null,
  "status": "PENDING",
  "paid": false,
  "destinationCalendarId": 99060,
  "cancellationReason": null,
  "rejectionReason": null,
  "dynamicEventSlugRef": null,
  "dynamicGroupSlugRef": null,
  "rescheduled": null,
  "fromReschedule": null,
  "recurringEventId": null,
  "smsReminderNumber": null,
  "scheduledJobs": [],
  "metadata": {
    "checkin": "true"
  },
  "isRecorded": false,
  "iCalUID": "[email protected]",
  "iCalSequence": 0,
  "rating": null,
  "ratingFeedback": null,
  "noShowHost": null,
  "user": {
    "email": null,
    "name": "Patrick Göler von Ravensburg",
    "timeZone": "Europe/Berlin",
    "username": "patrick-productlane"
  },
  "attendees": [
    {
      "id": 2358122,
      "email": "[email protected]",
      "name": "Patrick",
      "timeZone": "Europe/Berlin",
      "locale": "en",
      "bookingId": 1838535
    }
  ],
  "payment": [],
  "references": [],
  "luckyUsers": []
}

Those are the things I encountered when interacting with the API. If there's a better way to do those things, I'm all ears, and sorry if I missed something in the docs. Thanks!

CAL-3756

pgvr avatar Apr 22 '24 17:04 pgvr

To address the issues you're encountering with the Cal.com API:

  1. Create Booking Error: The error indicates a missing notes field in the responses object. Although not documented, include this field to resolve the error:

    "responses": {
      "name": "Patrick",
      "email": "[email protected]",
      "location": "",
      "notes": "Some notes here"
    }
    
  2. Unable to cancel booking via API: The 401 error suggests an issue with the API key or its permissions. Ensure the API key is correctly included, preferably in the request headers:

    headers: {
      'Authorization': `Bearer ${API_KEY}`
    }
    

    This might resolve the authorization issue.

  3. Workaround to cancel booking via public API: Your current workaround is practical. However, for stability, using official API endpoints is recommended. If problems persist, contacting Cal.com support could provide a more permanent solution.

  4. Unable to get eventTypeId for username and eventSlug: Currently, there's no direct API endpoint to retrieve eventTypeId using username and eventSlug. Your workaround using tRPC is a valid approach in the absence of a dedicated API endpoint for this purpose.

These steps should help you navigate the issues you've been facing with the API. If further clarification is needed, don't hesitate to ask.

Details

Sources


About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar Apr 22 '24 17:04 dosubot[bot]