Edits history of script submission #10742 for ' Create a New Tag (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a New Tag
     * To create a tag you can send a POST request to `/v2/tags` with a `name` attribute.
     */
    export async function main(
      auth: Digitalocean,
      body: {
        name?: string;
        resources?: { count?: number; last_tagged_uri?: string } & {
          droplets?: { count?: number; last_tagged_uri?: string };
          imgages?: { count?: number; last_tagged_uri?: string };
          volumes?: { count?: number; last_tagged_uri?: string };
          volume_snapshots?: { count?: number; last_tagged_uri?: string };
          databases?: { count?: number; last_tagged_uri?: string };
        };
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/tags`);
    
      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