//native
type Pinterest = {
token: string;
};
/**
* List ads
* List ads that meet the filters provided:
- Listed campaign ids or ad group ids or ad ids
- Listed entity statuses
If no filter is provided, all ads in the ad account are returned.
Note:
Provide only campaign_id or ad_group_id or ad_id. Do not provide more than one type.
Review status is provided for each ad; if review_status is REJECTED, the rejected_reasons field will contain additional information.
For more, see Pinterest advertising standards.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
campaign_ids: string | undefined,
ad_group_ids: string | undefined,
ad_ids: string | undefined,
entity_statuses: string | undefined,
page_size: string | undefined,
order: "ASCENDING" | "DESCENDING" | undefined,
bookmark: string | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ads`,
);
for (const [k, v] of [
["campaign_ids", campaign_ids],
["ad_group_ids", ad_group_ids],
["ad_ids", ad_ids],
["entity_statuses", entity_statuses],
["page_size", page_size],
["order", order],
["bookmark", bookmark],
]) {
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