//native
type Pinterest = {
token: string;
};
/**
* Get assets assigned to a member
* Get assets on which you assigned asset permissions to the given member. Can be used to:
- get all assets, regardless of asset type or
- get assets of one asset type by using the asset_type query.
The return response will include the permissions the member has to that asset and the asset type.
*/
export async function main(
auth: Pinterest,
business_id: string,
member_id: string,
asset_type: "AD_ACCOUNT" | "PROFILE" | "ASSET_GROUP" | undefined,
start_index: string | undefined,
bookmark: string | undefined,
page_size: string | undefined,
) {
const url = new URL(
`https://api.pinterest.com/v5/businesses/${business_id}/members/${member_id}/assets`,
);
for (const [k, v] of [
["asset_type", asset_type],
["start_index", start_index],
["bookmark", bookmark],
["page_size", page_size],
]) {
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