UNPKG

@cllbk/ghl

Version:

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

46 lines (40 loc) 1.09 kB
import { BadRequestDTO, UnauthorizedDTO, UnprocessableDTO, } from "../../types/_global"; import type { ProductsGetResponseDTO } from "../../types/products"; import { withExponentialBackoff } from "../../contexts/requestUtils"; const baseUrl = "https://services.leadconnectorhq.com/products"; type ResponseTypes = | ProductsGetResponseDTO | BadRequestDTO | UnauthorizedDTO | UnprocessableDTO; const get = async ( locationId: string, productId: string, authToken: string ): Promise<ResponseTypes> | null => { const fetchEvent = async () => { const URL = `${baseUrl}/${productId}?` + new URLSearchParams({ locationId }); 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;