@cllbk/ghl
Version:
A public Node.js compatible SDK for working with HighLevel's (GHL's) Version 2 API.
54 lines (47 loc) • 1.41 kB
text/typescript
import {
BadRequestDTO,
UnauthorizedDTO,
UnprocessableDTO,
} from "../../../types/_global";
import type {
CalendarGetCreateUpdateNoteSuccessfulResponseDto,
CalendarEventDTO,
CalendarGetNoteSchemaDTO,
} from "../../../types/calendars";
import { withExponentialBackoff } from "../../../contexts/requestUtils";
import { ContactNotesDTO } from "../../../types/contacts";
const baseUrl = "https://services.leadconnectorhq.com/calendars/appointments";
type ResponseTypes =
| CalendarGetCreateUpdateNoteSuccessfulResponseDto
| BadRequestDTO
| UnauthorizedDTO
| UnprocessableDTO;
const update = async (
appointmentId: CalendarEventDTO["id"],
noteId: CalendarGetNoteSchemaDTO["id"],
options: ContactNotesDTO,
authToken: string
): Promise<ResponseTypes> | null => {
const URL = `${baseUrl}/${appointmentId}/notes/${noteId}`;
const updateNote = async () => {
const response = await fetch(URL, {
method: "PUT",
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(updateNote);
} catch (error) {
console.error(error);
return null;
}
};
export default update;