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

[CAL-2745] API for getting an event type by slug

Open aecorredor opened this issue 1 year ago • 10 comments

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

CAL-2745

aecorredor avatar Nov 17 '23 15:11 aecorredor

/bounty 20

PeerRich avatar Nov 21 '23 23:11 PeerRich

💎 $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!

👉 Add a bountyShare on socials

algora-pbc[bot] avatar Nov 21 '23 23:11 algora-pbc[bot]

@alishaz-polymath this should be easy, no?

PeerRich avatar Nov 21 '23 23:11 PeerRich

I'm looking into this

jemiluv8 avatar Nov 22 '23 04:11 jemiluv8

@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 avatar Nov 22 '23 09:11 alishaz-polymath

/attempt #12411

Options

ouwargui avatar Nov 22 '23 10:11 ouwargui

@alishaz-polymath should i change v1/event-types/:id to v1/event-types/:id-or-slug for all HTTP methods?

ouwargui avatar Nov 22 '23 10:11 ouwargui

@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.

  1. this means that i have to change findUnique to findMany. https://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/event-types/%5Bid%5D/_get.ts#L47-L50

  2. 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 permissions https://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/event-types/%5Bid%5D/_get.ts#L85-L96

  3. and i'll also need to refactor this function in case the event-type is from a team https://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 id field inside the req.query, so it throws https://github.com/calcom/cal.com/blob/9a6683e01dace9cbe426ec35084e38201555085d/apps/api/pages/api/teams/%5BteamId%5D/_auth-middleware.ts#L25

ouwargui avatar Nov 22 '23 12:11 ouwargui

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.

alishaz-polymath avatar Nov 22 '23 13:11 alishaz-polymath

closed my pr in favor or #12491. Good job @ouwargui.

jemiluv8 avatar Nov 22 '23 15:11 jemiluv8

Is the issue still open ?

kesh-007 avatar Jan 23 '24 08:01 kesh-007

💡 @abhijeetsingh-22 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Jan 23 '24 21:01 algora-pbc[bot]

🎉🎈 @abhijeetsingh-22 has been awarded $20! 🎈🎊

algora-pbc[bot] avatar Feb 02 '24 15:02 algora-pbc[bot]