Edits history of script submission #11231 for ' Create lead forms (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create 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.
    
    Create lead forms. Lead forms are used in lead ads and allow you to control what text appears on the lead form’ s description, questions and confirmation sections.
    
    For more, see Lead ads.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        name?: string;
        privacy_policy_link?: string;
        has_accepted_terms?: false | true;
        completion_message?: string;
        status?: "DRAFT" | "ACTIVE";
        disclosure_language?: string;
        questions?: {
          question_type?:
            | "CUSTOM"
            | "FULL_NAME"
            | "FIRST_NAME"
            | "LAST_NAME"
            | "EMAIL"
            | "PHONE_NUMBER"
            | "ZIP_CODE"
            | "GENDER"
            | "CITY"
            | "COUNTRY"
            | "STATE_PROVINCE"
            | "ADDRESS"
            | "DATE_OF_BIRTH"
            | "AGE";
          custom_question_field_type?:
            | "TEXT_FIELD"
            | "TEXT_AREA"
            | "RADIO_LIST"
            | "CHECKBOX";
          custom_question_label?: string;
          custom_question_options?: string[];
        }[];
        policy_links?: { label?: string; link?: string }[];
      } & {}[],
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms`,
      );
    
      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