UNPKG

@cllbk/ghl

Version:

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

44 lines (38 loc) 1.05 kB
import { BadRequestDTO, UnauthorizedDTO, UnprocessableDTO, } from "../../types/_global"; import type { SnapshotsGetResponseDTO } from "../../types/snapshots"; import { withExponentialBackoff } from "../../contexts/requestUtils"; const baseUrl = "https://services.leadconnectorhq.com/snapshots"; type ResponseTypes = | SnapshotsGetResponseDTO | BadRequestDTO | UnauthorizedDTO | UnprocessableDTO; const get = async ( companyId: string, authToken: string ): Promise<ResponseTypes> | null => { const fetchEvent = async () => { const URL = `${baseUrl}?` + new URLSearchParams({ companyId }); const response = await fetch(URL, { method: "GET", headers: { Accept: "application/json", Version: "2021-07-28", Authorization: `Bearer ${authToken}`, }, }); const data: ResponseTypes = await response.json(); return data; }; try { return await withExponentialBackoff(fetchEvent); } catch (error) { console.error(error); return null; } }; export default get;