---
title: "Create or update a policy module"
method: PUT
path: "/v1/policies/{id}"
tags: ["Policy API"]
---

# Create or update a policy module

`PUT /v1/policies/{id}`

- If the policy module does not exist, it is created.
- If the policy module already exists, it is replaced.

If the policy module isn't correctly defined, a *bad request* (400) response is returned.

### Example policy module
```yaml
package opa.examples

import data.servers
import data.networks
import data.ports

public_servers[server] {
  some k, m
  	server := servers[_]
  	server.ports[_] == ports[k].id
  	ports[k].networks[_] == networks[m].id
  	networks[m].public == true
}
```

## Query parameters

- `pretty` boolean
- `metrics` boolean

## Response `200`

Success

- 200Result
  - `result` object[]
    - `id` string — The name of a policy module
    - `raw` string — A string representation of the full Rego policy
    - `ast` object — The types for declarations and runtime objects passed to your implementation. This consists of an abstract syntax tree (AST) of policy modules, package and import declarations, rules, expressions, and terms.
      - `package` object
        - `path` object[] — The path to the package
          - `type` 'import' | 'package' — The type of the path operation
          - `value` string — The path variable
      - `rules` object[] — When OPA evaluates a rule, it generates the content of a [virtual documents](https://www.openpolicyagent.org/docs/latest/philosophy/#the-opa-document-model)
        - `head` object
          - `name` string — The head of the rule
          - `key` object — The type/value pairing for this rule's head
            - `type` string — The type of the head
            - `value` string — The value of the head
        - `body` object[] — A list of the terms in this rule
          - `index` number — The location of this term in the list (starts at 0)
          - `terms` object[] — The type/value pairing for this term
            - `type` string — The type of the term variable
            - `value` object[] — The list of types and values for the term variable
              - …

## Other responses

- `400` — Bad request
- `500` — Server error

---

[API](https://skmtc.net/open-policy-agent/apis/open-policy-agent-opa-rest-api.md) · [All operations](https://skmtc.net/open-policy-agent/apis/open-policy-agent-opa-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/open-policy-agent/open-policy-agent-opa-rest-api/versions/47f6f2062932/schema)
