Edits history of script submission #15888 for ' Add form to portal (formstack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Formstack = {
      token: string;
    };
    /**
     * /portal/:id/form
     * Adds form to specified portal
     */
    export async function main(
      auth: Formstack,
      id: string,
      body: {
        name: string;
        formId: number;
        deadline?: string;
        description?: string;
        notifyUsers?: false | true;
      },
    ) {
      const url = new URL(`https://www.formstack.com/api/v2/portal/${id}/form`);
    
      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