cal.com
cal.com copied to clipboard
[CAL-2745] API for getting an event type by slug
Is your proposal related to a problem?
In our system, we handle appointment creation in a background process since we also have to create certain records in our own database. This background process needs to be retry-safe, and we're in need of a way to get an event type by slug from cal.com so we know if we've already created a specific unique event type in the case of a retry. Right now, there doesn't seem to be an API for fetching an event type by slug.
Describe the solution you'd like
We'd like to see an API for GET v1/event-types/:event-type-slug so we can fetch an event type by its unique slug.
Describe alternatives you've considered
Right now we're getting around this issue with a hacky solution: we make a request to the actual HTML page of the event type booking page at https://cal.com/booking/${uid}. If we get a 200, we know the event type was already created. If we get a 400, we know it hasn't.
Additional context
We couldn't find any related issue.
Requirement/Document
N/A
/bounty 20
💎 $20 bounty created by cal
👉 No need to comment asking to work on it. Just open a PR and claim the bounty with /claim #12411 inside the PR
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to calcom/cal.com!
@alishaz-polymath this should be easy, no?
I'm looking into this
@alishaz-polymath this should be easy, no?
Yeah, it should be straightforward. I think it would make sense to simply update the GET v1/event-types/:id to be something like GET v1/event-types/:id-or-slug
@alishaz-polymath should i change v1/event-types/:id to v1/event-types/:id-or-slug for all HTTP methods?
@alishaz-polymath @PeerRich
slug, different from id, is not an unique value. i'm having trouble trying to query it because it risks returning more than one event-type.
-
this means that i have to change
findUniquetofindMany. https://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/event-types/%5Bid%5D/_get.ts#L47-L50 -
which will return a list, so i'll have to refactor this function to iterate through the items and check which events the user has
permissionshttps://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/event-types/%5Bid%5D/_get.ts#L85-L96 -
and i'll also need to refactor this function in case the
event-typeis from ateamhttps://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/teams/%5BteamId%5D/_auth-middleware.ts#L20-L32
do you guys have any opinions on these steps or can i proceed?
also, i think i found a bug on this line, the schema don't expect to receive an
idfield inside thereq.query, so it throws https://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/teams/%5BteamId%5D/_auth-middleware.ts#L25
Event type slugs are unique on a per-user basis, so if you hook up userId in where clause along with the slug, the result should be unique. You could do findFirst there to achieve it.
closed my pr in favor or #12491. Good job @ouwargui.
Is the issue still open ?
💡 @abhijeetsingh-22 submitted a pull request that claims the bounty. You can visit your bounty board to reward.