> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kosli.com/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.kosli.com/feedback

```json
{
  "path": "/api-reference/policies/create-or-update-policy",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Create or update policy

> Create or update a Policy in an organization.



## OpenAPI

````yaml https://app.kosli.com/api/v2/openapi.json put /policies/{org}
openapi: 3.1.0
info:
  title: Kosli API
  summary: The API for communicating with Kosli
  description: >

    # Authentication 


    When making requests against Kosli API, you can authenticate your requests
    using a bearer token. 

    Set the bearer token in the request Authorization header to a valid API
    key. 

    API Keys can be personal or for service accounts. Check the [service
    accounts
    documentation](https://docs.kosli.com/getting_started/service-accounts/) for
    details. 


    ## Curl example


    ```shell

    curl -H "Authorization: Bearer <<your-api-key>>"
    https://app.kosli.com/api/v2/environments/<<your-org-name>>

    ```
  version: '2.0'
servers:
  - url: https://app.kosli.com/api/v2
    description: EU
  - url: https://app.us.kosli.com/api/v2
    description: US
security:
  - HTTPBearer: []
paths:
  /policies/{org}:
    put:
      tags:
        - Policies
      summary: Create or update policy
      description: Create or update a Policy in an organization.
      operationId: put_policy_policies__org__put
      parameters:
        - name: org
          in: path
          required: true
          schema:
            type: string
            title: Org
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_put_policy_policies__org__put'
      responses:
        '200':
          description: Update Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyResponse'
        '201':
          description: Creation Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PolicyResponse'
        '400':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/fastapi_app__errors__ValidationErrorResponse___locals___ValidationErrorResponseModel__10
        '413':
          description: Request Entity Too Large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequestEntityTooLargeResponseModel'
      security:
        - HTTPBearer: []
        - HTTPBasic: []
components:
  schemas:
    Body_put_policy_policies__org__put:
      properties:
        payload:
          $ref: '#/components/schemas/PolicyPutInput'
          description: Policy metadata in JSON format
        policy_file:
          anyOf:
            - type: string
              contentMediaType: application/octet-stream
            - type: 'null'
          title: Policy File
          description: 'The YAML policy file to upload (max size: 10MB)'
      type: object
      required:
        - payload
      title: Body_put_policy_policies__org__put
    PolicyResponse:
      properties:
        name:
          type: string
          title: Name
        description:
          type: string
          title: Description
        created_by:
          type: string
          title: Created By
        created_at:
          anyOf:
            - type: number
            - type: 'null'
          title: Created At
        last_modified_at:
          anyOf:
            - type: number
            - type: 'null'
          title: Last Modified At
        archived:
          type: boolean
          title: Archived
          default: false
        versions:
          items:
            $ref: '#/components/schemas/VersionedPolicy'
          type: array
          title: Versions
          default: []
        events:
          items:
            $ref: '#/components/schemas/PolicyEvent'
          type: array
          title: Events
          default: []
        consuming_envs:
          items:
            type: string
          type: array
          title: Consuming Envs
          default: []
      type: object
      required:
        - name
        - description
        - created_by
      title: PolicyResponse
      description: >-
        Response model for a policy


        This represents the response structure when retrieving, creating or
        updating a policy.
      examples:
        - archived: false
          consuming_envs:
            - production
          created_at: 1633123456
          created_by: John Doe
          description: Production environment policy
          events:
            - data:
                version: 1
              timestamp: 1633123456
              type: policy_created
              user: John Doe
          last_modified_at: 1633123456
          name: production-policy
          versions:
            - comment: Initial version
              created_by: John Doe
              policy_yaml: |-
                _schema: https://kosli.com/schemas/policy/environment/v1

                artifacts:
                  provenance:
                    required: false
              timestamp: 1633123456
              version: 1
    fastapi_app__errors__ValidationErrorResponse___locals___ValidationErrorResponseModel__10:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: ValidationErrorResponseModel
      examples:
        - errors:
            email: Field must be a valid email address
            name: Field cannot be empty
          message: Input payload validation failed
    RequestEntityTooLargeResponseModel:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: RequestEntityTooLargeResponseModel
      examples:
        - message: File size exceeds 10MB limit
    PolicyPutInput:
      properties:
        name:
          type: string
          pattern: ^[a-zA-Z0-9][a-zA-Z0-9\-_\.~]*$
          title: Name
          examples:
            - production-policy
        description:
          type: string
          title: Description
          default: ''
          examples:
            - some description
        type:
          type: string
          const: env
          title: Type
          default: env
        comment:
          type: string
          title: Comment
          default: ''
          examples:
            - describe what you changed
      additionalProperties: false
      type: object
      required:
        - name
      title: PolicyPutInput
      examples:
        - comment: Initial version
          description: Production environment policy
          name: production-policy
          type: env
    VersionedPolicy:
      properties:
        version:
          type: integer
          title: Version
        comment:
          type: string
          title: Comment
          default: ''
        timestamp:
          type: number
          title: Timestamp
        created_by:
          type: string
          title: Created By
        policy_yaml:
          type: string
          title: Policy Yaml
      additionalProperties: false
      type: object
      required:
        - version
        - timestamp
        - created_by
        - policy_yaml
      title: VersionedPolicy
    PolicyEvent:
      properties:
        type:
          type: string
          enum:
            - creation
            - metadata_update
            - new_version
            - renaming
            - archiving
          title: Type
        timestamp:
          type: number
          title: Timestamp
        user:
          type: string
          title: User
        data:
          additionalProperties: true
          type: object
          title: Data
      type: object
      required:
        - type
        - timestamp
        - user
      title: PolicyEvent
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````