UNPKG

@cllbk/ghl

Version:

A public Node.js compatible SDK for working with HighLevel's (GHL's) Version 2 API.

52 lines (45 loc) 1.27 kB
import { BadRequestDTO, UnauthorizedDTO, UnprocessableDTO, } from "../../../types/_global"; import type { CalendarCreateResourceDTO, CalendarResourceResponseDTO, CalendarResourceTypeDTO, } from "../../../types/calendars"; import { withExponentialBackoff } from "../../../contexts/requestUtils"; const baseUrl = "https://services.leadconnectorhq.com/calendars/resources"; type ResponseTypes = | CalendarResourceResponseDTO | BadRequestDTO | UnauthorizedDTO | UnprocessableDTO; const create = async ( resourceType: CalendarResourceTypeDTO, options: CalendarCreateResourceDTO, authToken: string ): Promise<ResponseTypes> | null => { const URL = `${baseUrl}/${resourceType}`; const createResource = async () => { const response = await fetch(URL, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json", Version: "2021-04-15", Authorization: `Bearer ${authToken}`, }, body: JSON.stringify(options), }); const data: ResponseTypes = await response.json(); return data; }; try { return await withExponentialBackoff(createResource); } catch (error) { console.error(error); return null; } }; export default create;