Edits history of script submission #15894 for ' Create form (formstack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Formstack = {
      token: string;
    };
    /**
     * /form
     * Create a new form in your account
     */
    export async function main(
      auth: Formstack,
      body: {
        name: string;
        db?: false | true;
        template?: string;
        num_columns?: number;
        label_position?: string;
        submit_button_title?: string;
        password?: string;
        use_ssl?: false | true;
        timezone?: string;
        language?: string;
        active?: false | true;
        disabled_message?: string;
        fields?: string[];
        notifications?: string[];
        confirmation?: string[];
        webhooks?: string;
      },
    ) {
      const url = new URL(`https://www.formstack.com/api/v2/form.json`);
    
      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 235 days ago