Edits history of script submission #9202 for ' Create Share (calendly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Calendly = {
    	token: string
    }
    
    export async function main(
    	auth: Calendly,
    	body: {
    		event_type: string
    		name?: string
    		duration?: number
    		duration_options?: number[]
    		period_type?: 'available_moving' | 'moving' | 'fixed' | 'unlimited'
    		start_date?: string
    		end_date?: string
    		max_booking_time?: number
    		hide_location?: false | true
    		location_configurations?: {
    			location?: string
    			additional_info?: string
    			phone_number?: string
    			position?: number
    			kind?:
    				| 'physical'
    				| 'ask_invitee'
    				| 'custom'
    				| 'outbound_call'
    				| 'inbound_call'
    				| 'google_conference'
    				| 'gotomeeting_conference'
    				| 'microsoft_teams_conference'
    				| 'webex_conference'
    				| 'zoom_conference'
    		}[]
    		availability_rule?: {
    			rules?: {
    				type?: 'wday' | 'date'
    				wday?: 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday'
    				date?: string
    				intervals?: { from?: string; to?: string }[]
    			}[]
    			timezone?: string
    		}
    	}
    ) {
    	const url = new URL(`https://api.calendly.com/shares`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 571 days ago