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

# Create an alert rule

> Create an alert rule



## OpenAPI

````yaml post /alert-rules
openapi: 3.0.0
info:
  title: Phare
  description: >-
    Learn how to use the phare.io API. Most of the things that can be done on
    the web platform can also be achieved with the API documented on this page.
  termsOfService: https://phare.io/legal/terms-of-service
  contact:
    name: Phare
    email: support@phare.io
  version: '1.0'
servers:
  - url: https://api.phare.io
security:
  - BearerAuth: []
tags:
  - name: Users
    description: Users
  - name: Projects
    description: Projects
  - name: Alert Rules
    description: Alert Rules
  - name: Monitors
    description: Monitors
  - name: Incidents
    description: Incidents
  - name: Status Pages
    description: Status Pages
  - name: Reports
    description: Reports
  - name: Platform
    description: Platform
  - name: Integrations
    description: Integrations
paths:
  /alert-rules:
    post:
      tags:
        - Alert Rules
      summary: Create an alert rule
      description: Create an alert rule
      operationId: createUptimeAlertRule
      parameters:
        - $ref: '#/components/parameters/header_project_id'
        - $ref: '#/components/parameters/header_project_slug'
      requestBody:
        description: Alert rule request
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                scope:
                  description: Scoped of the alert rule
                  type: string
                  example: organization
                  enum:
                    - organization
                    - project
                event:
                  $ref: '#/components/schemas/Uptime.ProductEvents'
                integration_id:
                  description: >-
                    The ID of the integration used to send a notification when
                    the alert rule is executed
                  type: integer
                  example: 1
                rate_limit:
                  description: >-
                    Minimum time in minutes between two executions of the alert
                    rule, used to minimized the number of alert received.
                  type: integer
                  example: 5
                  enum:
                    - 0
                    - 5
                    - 10
                    - 30
                    - 60
                    - 180
                    - 720
                    - 1440
                event_settings:
                  description: Additional settings for the event
                  anyOf:
                    - title: Empty
                      type: object
                      nullable: true
                    - $ref: >-
                        #/components/schemas/Platform.Event.UptimeIncident.AlertRuleSettings
                    - $ref: >-
                        #/components/schemas/Platform.Event.UptimeMonitorCertificateExpiring.AlertRuleSettings
                integration_settings:
                  description: Additional settings for the integration
                  anyOf:
                    - title: Empty
                      type: object
                      nullable: true
                    - $ref: '#/components/schemas/Platform.App.Ntfy.AlertRuleSettings'
                    - $ref: >-
                        #/components/schemas/Platform.App.OutgoingWebhook.AlertRuleSettings
                    - $ref: >-
                        #/components/schemas/Platform.App.Pushover.AlertRuleSettings
              required:
                - event
                - integration_id
                - rate_limit
      responses:
        '201':
          description: Success, alert rule created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    example: 1
                  project_id:
                    description: The ID of a project to use as a scope
                    type: integer
                    example: 1
                    nullable: true
                  event:
                    $ref: '#/components/schemas/Uptime.ProductEvents'
                  integration_id:
                    description: >-
                      The ID of the integration used to send a notification when
                      the alert rule is executed
                    type: integer
                    example: 1
                  rate_limit:
                    description: >-
                      Minimum time in minutes between two executions of the
                      alert rule, used to minimized the number of alert
                      received.
                    type: integer
                    example: 5
                    enum:
                      - 0
                      - 5
                      - 10
                      - 30
                      - 60
                      - 180
                      - 720
                      - 1440
                  event_settings:
                    description: Additional settings for the event
                    anyOf:
                      - title: Empty
                        type: object
                        nullable: true
                      - $ref: >-
                          #/components/schemas/Platform.Event.UptimeIncident.AlertRuleSettings
                      - $ref: >-
                          #/components/schemas/Platform.Event.UptimeMonitorCertificateExpiring.AlertRuleSettings
                  integration_settings:
                    description: Additional settings for the integration
                    anyOf:
                      - title: Empty
                        type: object
                        nullable: true
                      - $ref: >-
                          #/components/schemas/Platform.App.Ntfy.AlertRuleSettings
                      - $ref: >-
                          #/components/schemas/Platform.App.OutgoingWebhook.AlertRuleSettings
                      - $ref: >-
                          #/components/schemas/Platform.App.Pushover.AlertRuleSettings
                  created_at:
                    description: Date of creation for the entity
                    type: string
                    format: date-time
                  updated_at:
                    description: Date of last update for the entity
                    type: string
                    format: date-time
                required:
                  - event
                  - integration_id
                  - rate_limit
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '422':
          $ref: '#/components/responses/422'
components:
  parameters:
    header_project_id:
      name: X-Phare-Project-Id
      in: header
      description: A project header is required when using an organization-scoped API key.
      required: false
      schema:
        type: integer
        example: 1
    header_project_slug:
      name: X-Phare-Project-Slug
      in: header
      description: A project header is required when using an organization-scoped API key.
      required: false
      schema:
        type: string
        example: luminous-guiding-tower
  schemas:
    Uptime.ProductEvents:
      type: string
      enum:
        - uptime.monitor.created
        - uptime.monitor.deleted
        - uptime.monitor_certificate.discovered
        - uptime.monitor_certificate.expiring
        - uptime.incident.created
        - uptime.incident.propagated
        - uptime.incident.partially_recovered
        - uptime.incident.recovered
        - uptime.incident_comment.created
        - uptime.incident_update.published
    Platform.Event.UptimeIncident.AlertRuleSettings:
      title: Uptime incident
      required:
        - type
      properties:
        type:
          description: Type of incident to notify about
          type: string
          example: all
          enum:
            - all
            - monitor
            - manual
      type: object
    Platform.Event.UptimeMonitorCertificateExpiring.AlertRuleSettings:
      title: Uptime certificate expiring
      required:
        - days_before_expiry
      properties:
        days_before_expiry:
          description: Days to notify before the certificate expires
          type: integer
          example: 25
          maximum: 60
          minimum: 1
      type: object
    Platform.App.Ntfy.AlertRuleSettings:
      title: Ntfy
      required:
        - priority
      properties:
        priority:
          description: Notification priority level
          type: string
          example: default
          enum:
            - min
            - low
            - default
            - high
            - max
      type: object
    Platform.App.OutgoingWebhook.AlertRuleSettings:
      title: Outgoing Webhooks
      required:
        - schema
      properties:
        schema:
          description: JSON schema defining the webhook payload structure
          type: string
          format: json
          example: '{"id": "{{ alert_rule_request.id }}", "event": "{{ event.key }}"}'
          maxLength: 5000
      type: object
    Platform.App.Pushover.AlertRuleSettings:
      title: Pushover
      properties:
        priority:
          description: Notification priority level
          type: string
          example: normal
          enum:
            - lowest
            - low
            - normal
            - high
            - emergency
        retry:
          description: Retry interval in seconds (required for emergency priority)
          type: integer
          example: 300
          nullable: true
          maximum: 86400
          minimum: 30
        expire:
          description: Expiration time in seconds (required for emergency priority)
          type: integer
          example: 3600
          nullable: true
          maximum: 10800
          minimum: 30
      type: object
  responses:
    '401':
      description: Error, access unauthorized
      content:
        application/json:
          schema:
            description: Access unauthorized error schema
            properties:
              message:
                type: string
                example: Unauthorized
            type: object
    '403':
      description: Error, access forbidden
      content:
        application/json:
          schema:
            description: Access forbidden error schema
            properties:
              message:
                type: string
                example: >-
                  The platform:write permission is required to perform this
                  action.
            type: object
    '422':
      description: Error, unprocessable entity
      content:
        application/json:
          schema:
            description: Validation error schema
            properties:
              message:
                type: string
              errors:
                properties:
                  key:
                    type: array
                    items:
                      type: string
                      example: The key field is required
                type: object
            type: object
  securitySchemes:
    BearerAuth:
      type: http
      description: >-
        Use a user token to access authenticated routes. The token must be
        specified in the Authorization HTTP header with the following format
        'Authorization: Bearer <token>'.
      scheme: bearer

````