Edits history of script submission #11386 for ' Update audience sharing between ad accounts (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Update audience sharing between ad accounts
     * From an ad account, share a specific audience with another ad account, or revoke access to a previously shared audience. Only the audience owner account can share the audience. The recipient ad account(s) must be in the same Pinterest Business Hierarchy as the business owner of the ad account. This endpoint is not available to all apps.Learn more.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: { audience_id?: string; operation_type?: "SHARE" | "REVOKE" } & {
        recipient_account_ids: string[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/audiences/ad_accounts/shared`,
      );
    
      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