//native
type Discourse = {
apiKey: string;
defaultHost: string;
apiUsername: string;
};
/**
* Create topic timer
*
*/
export async function main(
auth: Discourse,
id: string,
Api_Key: string,
Api_Username: string,
body: {
time?: string;
status_type?: string;
based_on_last_post?: false | true;
category_id?: number;
},
) {
const url = new URL(`https://${auth.defaultHost}/t/${id}/timer.json`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"API-KEY": auth.apiKey,
"API-USERNAME": auth.apiUsername,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago