//native
type Pinterest = {
token: string;
};
/**
* Get user account analytics
* Get analytics for the "operation user_account"
- 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,
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,
split_field:
| "NO_SPLIT"
| "APP_TYPE"
| "OWNED_CONTENT"
| "SOURCE"
| "PIN_FORMAT"
| undefined,
ad_account_id: string | undefined,
) {
const url = new URL(`https://api.pinterest.com/v5/user_account/analytics`);
for (const [k, v] of [
["start_date", start_date],
["end_date", end_date],
["from_claimed_content", from_claimed_content],
["pin_format", pin_format],
["app_types", app_types],
["content_type", content_type],
["source", source],
["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