Edits history of script submission #15922 for ' Get form partial submissions (formstack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Formstack = {
      token: string;
    };
    /**
     * /form/:id/partialsubmission
     * Get all partial submissions for the specified form
     */
    export async function main(
      auth: Formstack,
      id: string,
      encryption_password: string | undefined,
      min_time: string | undefined,
      max_time: string | undefined,
      search_field_x: string | undefined,
      search_value_x: string | undefined,
      page: string | undefined,
      per_page: string | undefined,
      sort: string | undefined,
      data: string | undefined,
      expand_data: string | undefined,
    ) {
      const url = new URL(
        `https://www.formstack.com/api/v2/form/${id}/partialsubmission.json`,
      );
      for (const [k, v] of [
        ["encryption_password", encryption_password],
        ["min_time", min_time],
        ["max_time", max_time],
        ["search_field_x", search_field_x],
        ["search_value_x", search_value_x],
        ["page", page],
        ["per_page", per_page],
        ["sort", sort],
        ["data", data],
        ["expand_data", expand_data],
      ]) {
        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 235 days ago