Edits history of script submission #11877 for ' Create Survey (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * Create Survey
     *
     */
    export async function main(
      auth: Buttondown,
      body: {
        identifier: string;
        question: string;
        answers: string[];
        notes?: string;
        is_freeform_response_enabled?: false | true;
        response_cadence?: "once" | "once_per_email";
      },
    ) {
      const url = new URL(`https://api.buttondown.com/v1/surveys`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Token " + 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 428 days ago