Edits history of script submission #11201 for ' Assign/Update member asset permissions (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Assign/Update member asset permissions
     * Grant multiple members access to assets and/or update multiple member's exisiting permissions to an asset.
    Note: Not all listed permissions are applicable to each asset type. For example, PROFILE_PUBLISHER would not be applicable to an asset of type AD_ACCOUNT. The permission level PROFILE_PUBLISHER is only available to an asset of the type PROFILE.
    
     */
    export async function main(
      auth: Pinterest,
      business_id: string,
      body: {
        accesses: {
          asset_id: string;
          member_id: string;
          permissions:
            | "ADMIN"
            | "ANALYST"
            | "FINANCE_MANAGER"
            | "AUDIENCE_MANAGER"
            | "CAMPAIGN_MANAGER"
            | "CATALOGS_MANAGER"
            | "PROFILE_PUBLISHER"[];
        }[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/businesses/${business_id}/members/assets/access`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago