//native
type Pinterest = {
token: string;
};
/**
* Get available metrics' definitions
* Get the definitions for ads and organic metrics available across both synchronous and asynchronous report endpoints.
The `display_name` attribute will match how the metric is named in our native tools like Ads Manager.
See Organic Analytics and Ads Analytics for more information.
*/
export async function main(
auth: Pinterest,
report_type: "SYNC" | "ASYNC" | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/resources/delivery_metrics`,
);
for (const [k, v] of [["report_type", report_type]]) {
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 537 days ago