Edits history of script submission #10734 for ' Create a New Domain Record (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a New Domain Record
     * To create a new record to a domain, send a POST request to
    `/v2/domains/$DOMAIN_NAME/records`.
    
    The request must include all of the required fields for the domain record type
    being added.
    
    See the [attribute table](#tag/Domain-Records) for details regarding record
    types and their respective required attributes.
    
     */
    export async function main(
      auth: Digitalocean,
      domain_name: string,
      body: {
        id?: number;
        type: string;
        name?: string;
        data?: string;
        priority?: number;
        port?: number;
        ttl?: number;
        weight?: number;
        flags?: number;
        tag?: string;
      } & {},
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/domains/${domain_name}/records`,
      );
    
      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 536 days ago