// 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> = {
id: string;
createdAt: string;
updatedAt: string;
archived: boolean;
properties: {
createdate: string;
hs_lastmodifieddate: string;
hs_object_id: string;
} & TObj;
};
export async function main<Props extends Record<PropertyKey, string>>(
hubspot: wmill.Resource<"hubspot">,
ticketId: number,
properties: Props,
): Promise<HS<Props>> {
const res = await fetch(
"https://api.hubapi.com/crm/v3/objects/tickets/" + ticketId,
{
headers: {
Authorization: `Bearer ${hubspot.token}`,
Accept: "application/json",
"content-type": "application/json",
},
method: "PATCH",
body: JSON.stringify({
properties,
}),
},
);
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