1
1
import calCom from "../../cal_com.app.mjs" ;
2
+ import { ConfigurationError } from "@pipedream/platform" ;
2
3
3
4
export default {
4
5
key : "cal_com-create-booking" ,
5
6
name : "Create Booking" ,
6
- description : "Create a new booking. [See the docs here ](https://developer.cal.com/api/api-reference/bookings#create-a-new-booking)" ,
7
- version : "0.0.1 " ,
7
+ description : "Create a new booking. [See the documentation ](https://developer.cal.com/api/api-reference/bookings#create-a-new-booking)" ,
8
+ version : "0.0.2 " ,
8
9
type : "action" ,
9
10
props : {
10
11
calCom,
11
- eventType : {
12
+ eventTypeId : {
12
13
propDefinition : [
13
14
calCom ,
14
- "eventType " ,
15
+ "eventTypeId " ,
15
16
] ,
16
17
} ,
17
18
name : {
@@ -33,12 +34,12 @@ export default {
33
34
startTime : {
34
35
type : "string" ,
35
36
label : "Start Time" ,
36
- description : "The start time of the new booking in **ISO 8601** format" ,
37
+ description : "The start time of the new booking in **ISO 8601** format. E.g. `2025-04-21T20:28:00` " ,
37
38
} ,
38
39
endTime : {
39
40
type : "string" ,
40
41
label : "End Time" ,
41
- description : "The end time of the new booking in **ISO 8601** format" ,
42
+ description : "The end time of the new booking in **ISO 8601** format. E.g. `2025-04-21T20:28:00` " ,
42
43
} ,
43
44
recurringCount : {
44
45
type : "integer" ,
@@ -61,7 +62,7 @@ export default {
61
62
} ,
62
63
async run ( { $ } ) {
63
64
const data = {
64
- eventTypeId : this . eventType ,
65
+ eventTypeId : this . eventTypeId ,
65
66
name : this . name ,
66
67
email : this . email ,
67
68
title : this . title ,
@@ -74,11 +75,19 @@ export default {
74
75
customInputs : [ ] ,
75
76
metadata : { } ,
76
77
} ;
77
- const response = await this . calCom . createBooking ( {
78
- data,
79
- $,
80
- } ) ;
81
- $ . export ( "$summary" , `Successfully created booking with ID ${ response . id } ` ) ;
82
- return response ;
78
+ try {
79
+ const response = await this . calCom . createBooking ( {
80
+ data,
81
+ $,
82
+ } ) ;
83
+ $ . export ( "$summary" , `Successfully created booking with ID ${ response . id } ` ) ;
84
+ return response ;
85
+ } catch ( error ) {
86
+ const errorJson = JSON . parse ( error . slice ( error . indexOf ( "{" ) ) ) ;
87
+ const message = errorJson ?. data ?. message ;
88
+ throw new ConfigurationError ( `Error: ${ message } ${ message === "no_available_users_found_error"
89
+ ? ". No users are available to be assigned to a booking at the specified time"
90
+ : "" } `) ;
91
+ }
83
92
} ,
84
93
} ;
0 commit comments