//native
type Tomorrow = {
apiKey: string;
};
/**
* Create an Insight
*
*/
export async function main(
auth: Tomorrow,
body: {
name: string;
rules?: string;
conditions?: string;
tags?: string[];
severity?: string;
description?: string;
},
Accept_Encoding?: string,
) {
const url = new URL(`https://api.tomorrow.io/v4/insights`);
const response = await fetch(url, {
method: "POST",
headers: {
...(Accept_Encoding ? { "Accept-Encoding": Accept_Encoding } : {}),
"Content-Type": "application/json",
ApiKey: auth.apiKey,
},
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