Edits history of script submission #11355 for ' List lead forms (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * List lead forms
     * This feature is currently in beta and not available to all apps, if you're interested in joining the beta, please reach out to your Pinterest account manager.
    
    List lead forms associated with an ad account ID.
    
    For more, see Lead ads.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      page_size: string | undefined,
      order: "ASCENDING" | "DESCENDING" | undefined,
      bookmark: string | undefined,
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms`,
      );
      for (const [k, v] of [
        ["page_size", page_size],
        ["order", order],
        ["bookmark", bookmark],
      ]) {
        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 537 days ago