Edits history of script submission #11398 for ' Update lead forms (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Update 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.
    
    Update lead forms. Lead ads help you reach people who are actively looking for, and interested in, your goods and services. The lead form can be associated with an ad to allow people to fill out the form.
    
    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 }[];
      } & { id: string }[],
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms`,
      );
    
      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