//native
type Miro = {
token: string;
};
/**
* Get app metrics
* Returns a list of usage metrics for a specific app for a given time range, grouped by requested time period.
This endpoint requires an app management API token. It can be generated in the Your Apps section of Developer Hub.
Required scope boards:read
Rate limiting Level 1
*/
export async function main(
auth: Miro,
app_id: string,
startDate: string | undefined,
endDate: string | undefined,
period: "DAY" | "WEEK" | "MONTH" | undefined,
) {
const url = new URL(
`https://api.miro.com//v2-experimental/apps/${app_id}/metrics`,
);
for (const [k, v] of [
["startDate", startDate],
["endDate", endDate],
["period", period],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
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