Edits history of script submission #11224 for ' Create customer lists (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create customer lists
     * Create a customer list from your records(hashed or plain-text email addresses, or hashed MAIDs or IDFAs).
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        name: string;
        records: string;
        list_type?:
          | "EMAIL"
          | "IDFA"
          | "MAID"
          | "LR_ID"
          | "DLX_ID"
          | "HASHED_PINNER_ID";
        exceptions?: {};
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/customer_lists`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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