//native
type Holded = {
apiKey: string;
};
/**
* Get available slots for location
* Get a list of available time slots for a location, specifying a service and a date.
*/
export async function main(
auth: Holded,
locationId: string,
serviceId: string | undefined,
day: string | undefined,
) {
const url = new URL(
`https://api.holded.com/api/crm/v1/bookings/locations/${locationId}/slots`,
);
for (const [k, v] of [
["serviceId", serviceId],
["day", day],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
key: auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago