Edits history of script submission #11389 for ' Update audience sharing from an ad account to businesses (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Update audience sharing from an ad account to businesses
     * From an ad account, share a specific audience with a business account, or revoke access to a previously shared audience. Only the audience owner account can share the audience. The recipient business account must be in the same 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_business_ids: string[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/audiences/businesses/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