//native
type Pinterest = {
token: string;
};
/**
* Get assets assigned to a partner or assets assigned by a partner
* Can be used to get the business assets your partner has granted you access to or the business assets you have
granted your partner access to. If you specify:
- partner_type=INTERNAL, you will retrieve your business assets that the partner has access to.
- partner_type=EXTERNAL, you will retrieve the partner's business assets that the partner has granted you access to.
*/
export async function main(
auth: Pinterest,
business_id: string,
partner_id: string,
partner_type: string | undefined,
asset_type: "AD_ACCOUNT" | "PROFILE" | "ASSET_GROUP" | undefined,
start_index: string | undefined,
page_size: string | undefined,
bookmark: string | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/businesses/${business_id}/partners/${partner_id}/assets`,
);
for (const [k, v] of [
["partner_type", partner_type],
["asset_type", asset_type],
["start_index", start_index],
["page_size", page_size],
["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