{
  "openapi": "3.0.3",
  "info": {
    "title": "Action Automation Connector REST",
    "version": "v1",
    "description": ""
  },
  "servers": [
    {
      "url": "https://cloud.kaaiot.com/aac/api/v1",
      "description": "API Server"
    }
  ],
  "paths": {
    "/automations": {
      "get": {
        "description": "Returns automations handled by the service.",
        "responses": {
          "200": {
            "description": "Automations are successfully retrieved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AutomationsResponse"
                },
                "example": [
                  {
                    "automationType": "command-invocation"
                  },
                  {
                    "automationType": "email-notification",
                    "schema": {
                      "$schema": "http://json-schema.org/draft-06/schema",
                      "title": "Email",
                      "description": "Email notification automation",
                      "type": "object",
                      "properties": {
                        "recipient": {
                          "description": "Email recipient",
                          "type": "string"
                        },
                        "subject": {
                          "description": "Email subject",
                          "type": "string"
                        },
                        "text": {
                          "description": "Email text",
                          "type": "string"
                        }
                      },
                      "required": [
                        "recipient",
                        "subject",
                        "text"
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/notification-types/{notificationType}/recipients": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        }
      ],
      "get": {
        "description": "Returns available email notification recipients.",
        "responses": {
          "200": {
            "description": "Email notification recipients are successfully retrieved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailNotificationRecipients"
                },
                "example": [
                  {
                    "id": 159,
                    "recipient": "usb@auto.logistic.com",
                    "state": "VERIFIED"
                  },
                  {
                    "id": 246,
                    "recipient": "krsn.company@gmail.com",
                    "state": "UNVERIFIED"
                  }
                ]
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "description": "Email notification recipient verification state.",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "VERIFIED",
                "UNVERIFIED"
              ]
            }
          }
        ]
      },
      "post": {
        "description": "Creates new email notification recipient.",
        "responses": {
          "201": {
            "description": "Unverified email notification recipient was successfully created. The verification email was sent to the specified email.",
            "headers": {
              "Location": {
                "description": "URI in format `{schema}://{host}:{port}/api/v1/notification-types/email/recipients/{id}`",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:create"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateEmailNotificationRecipient"
              }
            }
          }
        }
      }
    },
    "/notification-types/{notificationType}/recipients/{recipientId}": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        },
        {
          "name": "recipientId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "description": "Email recipient ID",
          "example": 351
        }
      ],
      "get": {
        "description": "Returns email notification recipient.",
        "responses": {
          "200": {
            "description": "Email notification recipient is successfully retrieved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailNotificationRecipient"
                },
                "example": {
                  "id": 159,
                  "recipient": "usb@auto.logistic.com",
                  "state": "VERIFIED"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:read"
            ]
          }
        ]
      },
      "delete": {
        "description": "Deletes email notification recipient.",
        "responses": {
          "204": {
            "description": "Email notification recipient successfully deleted."
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:update"
            ]
          }
        ]
      }
    },
    "/notification-types/{notificationType}/recipients/{recipientId}/verification": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        },
        {
          "name": "recipientId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "description": "Email recipient ID",
          "example": 351
        }
      ],
      "post": {
        "description": "Resends notification recipient verification email.",
        "responses": {
          "200": {
            "description": "A verification email has been successfully sent."
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:read"
            ]
          }
        ]
      }
    },
    "/notification-types/{notificationType}/recipients/{recipientId}/verification/{token}": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        },
        {
          "name": "recipientId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "description": "Email recipient ID",
          "example": 351
        }
      ],
      "get": {
        "description": "Verifies email notification recipient.",
        "responses": {
          "200": {
            "description": "Email notification recipient successfully verified."
          }
        }
      }
    },
    "/notification-types/{notificationType}/recipients/verify": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        }
      ],
      "put": {
        "description": "Verifies recipient on demand.",
        "responses": {
          "200": {
            "description": "Recipients have been successfully verified."
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:notification-recipient:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array"
              }
            }
          }
        }
      }
    },
    "/notification-types/{notificationType}/templates/verification": {
      "parameters": [
        {
          "name": "notificationType",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Notification type",
          "example": "email"
        }
      ],
      "get": {
        "description": "Retrieves verification email template.",
        "responses": {
          "200": {
            "description": "Item is successfully retrieved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                },
                "example": {
                  "subject": "Kaa email verification",
                  "template": "<!DOCTYPE html><html><body></body></html>"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:email-template:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "description": "Tenant ID. If omitted, the tenant ID of the authenticated principal will be used.",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "description": "Updates verification email template.",
        "responses": {
          "201": {
            "description": "Item is successfully updated."
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "tenant:email-template:update"
            ]
          }
        ],
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "description": "Tenant ID. If omitted, the tenant ID of the authenticated principal will be used.",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "subject": "Kaa email verification",
                "template": "<!DOCTYPE html><html><body></body></html>"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth_2_0": {
        "type": "oauth2",
        "description": "AAC supports OAuth 2.0 for authenticating all API requests.\n",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://auth.example.com/oauth/authorize",
            "scopes": {}
          }
        }
      }
    },
    "schemas": {
      "AutomationsResponse": {},
      "EmailNotificationRecipients": {
        "description": "Array of email notification recipients."
      },
      "CreateEmailNotificationRecipient": {
        "type": "object",
        "properties": {
          "recipient": {
            "type": "string",
            "description": "Email notification recipient."
          }
        },
        "required": [
          "recipient"
        ]
      },
      "EmailNotificationRecipient": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Email notification recipient unique identifier."
          },
          "recipient": {
            "type": "string",
            "description": "Email notification recipient."
          },
          "state": {
            "type": "string",
            "description": "Email notification recipient verification state.",
            "enum": [
              "VERIFIED",
              "UNVERIFIED"
            ]
          }
        },
        "required": [
          "id",
          "recipient",
          "state"
        ]
      },
      "Item": {
        "type": "object",
        "properties": {
          "subject": {
            "type": "string",
            "description": "Subject of the verification email."
          },
          "template": {
            "type": "string",
            "description": "HTML content of the verification email.\nCan contain next placeholders:\n<ul>\n  <li>{{accountUrl}}</li>\n  <li>{{year}}</li>\n</ul>\n"
          }
        },
        "required": [
          "subject",
          "template"
        ]
      },
      "AutomationResponse": {
        "type": "object",
        "properties": {
          "automationType": {
            "type": "string",
            "description": "Automation type."
          },
          "schema": {
            "type": "object",
            "description": "Automation body JSON schema."
          }
        }
      },
      "ClientErrorResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Detailed error description."
          }
        },
        "required": [
          "message"
        ]
      }
    }
  }
}