Edits history of script submission #10710 for ' Assign Resources to a Project (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Assign Resources to a Project
     * To assign resources to a project, send a POST request to `/v2/projects/$PROJECT_ID/resources`.
     */
    export async function main(
      auth: Digitalocean,
      project_id: string,
      body: { resources?: string[] },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/projects/${project_id}/resources`,
      );
    
      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