//native
type Pinterest = {
token: string;
};
/**
* Get user account top pins analytics
* Gets analytics data about a user's top pins (limited to the top 50).
- By default, the "operation user_account" is the token user_account.
Optional: Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account".
*/
export async function main(
auth: Pinterest,
start_date: string | undefined,
end_date: string | undefined,
sort_by:
| "ENGAGEMENT"
| "IMPRESSION"
| "OUTBOUND_CLICK"
| "PIN_CLICK"
| "SAVE"
| undefined,
from_claimed_content: "OTHER" | "CLAIMED" | "BOTH" | undefined,
pin_format:
| "ALL"
| "ORGANIC_IMAGE"
| "ORGANIC_PRODUCT"
| "ORGANIC_VIDEO"
| "ADS_STANDARD"
| "ADS_PRODUCT"
| "ADS_VIDEO"
| "ADS_IDEA"
| undefined,
app_types: "ALL" | "MOBILE" | "TABLET" | "WEB" | undefined,
content_type: "ALL" | "PAID" | "ORGANIC" | undefined,
source: "ALL" | "YOUR_PINS" | "OTHER_PINS" | undefined,
metric_types: string | undefined,
num_of_pins: string | undefined,
created_in_last_n_days: "30" | undefined,
ad_account_id: string | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/user_account/analytics/top_pins`,
);
for (const [k, v] of [
["start_date", start_date],
["end_date", end_date],
["sort_by", sort_by],
["from_claimed_content", from_claimed_content],
["pin_format", pin_format],
["app_types", app_types],
["content_type", content_type],
["source", source],
["metric_types", metric_types],
["num_of_pins", num_of_pins],
["created_in_last_n_days", created_in_last_n_days],
["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