@cllbk/ghl
Version:
A public Node.js compatible SDK for working with HighLevel's (GHL's) Version 2 API.
50 lines (44 loc) • 1.24 kB
text/typescript
import {
BadRequestDTO,
UnauthorizedDTO,
UnprocessableDTO,
} from "../../../types/_global";
import type {
ProductsPriceCreateDTO,
ProductsPriceCreateResponseDTO,
} from "../../../types/products";
import { withExponentialBackoff } from "../../../contexts/requestUtils"; // Assuming this function is defined
const baseUrl = "https://services.leadconnectorhq.com/products";
type ResponseTypes =
| ProductsPriceCreateResponseDTO
| BadRequestDTO
| UnauthorizedDTO
| UnprocessableDTO;
const create = async (
productId: string,
options: ProductsPriceCreateDTO,
authToken: string
): Promise<ResponseTypes> | null => {
const execute = async () => {
const URL = `${baseUrl}/${productId}/price`;
const response = await fetch(URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Version: "2021-07-28",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify(options),
});
const data: ResponseTypes = await response.json();
return data;
};
try {
return await withExponentialBackoff(execute);
} catch (error) {
console.error(error);
return null;
}
};
export default create;