//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* Download a statistic
* Download CSV-formatted data of a statistic.
*/
export async function main(
auth: Gorgias,
name:
| "overview"
| "total-tickets-created"
| "total-tickets-replied"
| "total-tickets-closed"
| "total-messages-sent"
| "total-messages-received"
| "median-first-response-time"
| "median-resolution-time"
| "total-one-touch-tickets"
| "support-volume"
| "resolution-time"
| "first-response-time"
| "tickets-created-per-hour-per-weekday"
| "tickets-per-tag"
| "tickets-created-per-channel"
| "tickets-created-per-channel-per-day"
| "tickets-closed-per-agent"
| "tickets-closed-per-agent-per-day"
| "messages-sent-per-macro"
| "satisfaction-surveys"
| "latest-satisfaction-surveys"
| "intents-occurrence"
| "intents-overview"
| "intents-breakdown-per-day"
| "revenue-overview"
| "revenue-per-agent"
| "revenue-per-day"
| "revenue-per-ticket"
| "automation-overview"
| "automation-flow"
| "automation-per-channel"
| "self-service-overview"
| "self-service-flows-distribution"
| "self-service-product-with-most-issues"
| "self-service-top-reported-issues"
| "self-service-most-returned-products",
body: {
filters: {
channels?: string[];
period?: { end_datetime: string; start_datetime: string };
score?: number[];
integrations?: number[];
agents?: number[];
tags?: number[];
};
},
) {
const url = new URL(
`https://${auth.domain}.gorgias.com/api/stats/${name}/download`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago