// Ctrl+. to cache dependencies on imports hover, Ctrl+S to format.
import * as wmill from "https://deno.land/x/windmill@v1.78.0/mod.ts";
type HS<TObj extends readonly string[]> = {
id: string;
createdAt: string;
updatedAt: string;
archived: boolean;
properties:
& {
createdate: string;
hs_lastmodifieddate: string;
hs_object_id: string;
}
& {
[TIndex in TObj[number]]: string;
};
};
export async function main<Props extends readonly string[]>(
hubspot: wmill.Resource<"hubspot">,
ticketId: number,
properties: Props,
): Promise<HS<Props>> {
let props;
if (properties.length > 0) {
props = "?properties=" + properties.join();
} else {
props = "";
}
const res = await fetch(
"https://api.hubapi.com/crm/v3/objects/tickets/" + ticketId + props,
{
headers: {
Authorization: `Bearer ${hubspot.token}`,
Accept: "application/json",
"content-type": "application/json",
},
method: "GET",
},
);
if (!res.ok) {
console.error(res);
throw new Error(res.statusText);
}
const jsonRes = await res.json();
if (jsonRes.status == "error") {
console.error(jsonRes);
throw new Error(jsonRes.message);
}
return jsonRes;
}
Submitted by sindre svendby964 614 days ago