//native
type Pinterest = {
token: string;
};
/**
* Get Pin analytics
* Get analytics for a Pin owned by the "operation user_account" - or on a group board that has been shared with this account.
*/
export async function main(
auth: Pinterest,
pin_id: string,
start_date: string | undefined,
end_date: string | undefined,
app_types: "ALL" | "MOBILE" | "TABLET" | "WEB" | undefined,
metric_types: string | undefined,
split_field: "NO_SPLIT" | "APP_TYPE" | undefined,
ad_account_id: string | undefined,
) {
const url = new URL(`https://api.pinterest.com/v5/pins/${pin_id}/analytics`);
for (const [k, v] of [
["start_date", start_date],
["end_date", end_date],
["app_types", app_types],
["metric_types", metric_types],
["split_field", split_field],
["ad_account_id", ad_account_id],
]) {
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 536 days ago