# Delete

Delete a rule. Fails if the rule is assigned to any agent.





```http
DELETE /api/public/v1/artifacts/rules/{rule_id}
```

## Example [#example]

<Tabs items="[&#x22;bash&#x22;, &#x22;TypeScript&#x22;, &#x22;Ruby&#x22;, &#x22;Python&#x22;, &#x22;Go&#x22;]">
  <Tab value="bash">
    ```bash
    curl -X DELETE https://api.nairi.ai/api/public/v1/artifacts/rules/RULE_ID \
      -H "Authorization: Bearer $NAIRI_API_KEY"
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    await fetch(`https://api.nairi.ai/api/public/v1/artifacts/rules/${ruleId}`, {
      method: "DELETE",
      headers: {
        Authorization: `Bearer ${process.env.NAIRI_API_KEY}`,
      },
    });
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require "net/http"
    require "uri"

    uri = URI("https://api.nairi.ai/api/public/v1/artifacts/rules/#{rule_id}")
    req = Net::HTTP::Delete.new(uri)
    req["Authorization"] = "Bearer #{ENV['NAIRI_API_KEY']}"

    Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import os
    import requests

    requests.delete(
        f"https://api.nairi.ai/api/public/v1/artifacts/rules/{rule_id}",
        headers={"Authorization": f"Bearer {os.environ['NAIRI_API_KEY']}"},
    )
    ```
  </Tab>

  <Tab value="Go">
    ```go
    package main

    import (
    	"net/http"
    	"os"
    )

    func main() {
    	ruleID := os.Getenv("RULE_ID")
    	req, _ := http.NewRequest("DELETE", "https://api.nairi.ai/api/public/v1/artifacts/rules/"+ruleID, nil)
    	req.Header.Set("Authorization", "Bearer "+os.Getenv("NAIRI_API_KEY"))
    	res, _ := http.DefaultClient.Do(req)
    	defer res.Body.Close()
    }
    ```
  </Tab>
</Tabs>

<Callout type="info">
  Deletion fails with `400 Bad Request` if the rule is assigned to any agent. Unassign it from every agent first (see [Agent resources](/api/agent-resources/unassign)).
</Callout>

## Response: `204 No Content` [#response-204-no-content]

## Error responses [#error-responses]

| HTTP  | Body                                                           | When                                                     |
| ----- | -------------------------------------------------------------- | -------------------------------------------------------- |
| `400` | `{"error":"cannot delete rule: still assigned to N agent(s)"}` | The rule is still attached to one or more agents.        |
| `404` | `{"error":"rule not found"}`                                   | No rule with that ID exists in the calling organization. |
