{
  "openapi": "3.1.0",
  "info": {
    "description": "This API allows managing connections between accounts.\n\nConnections are used to establish a one-way relationship between two accounts in the same hierarchy. If a bidirectional relationship is needed, two connections must be created.\n\nConnections allow for certain workflows between accounts, such as sharing or transferring assets.\n",
    "title": "Account Connections",
    "version": "1.0"
  },
  "externalDocs": {
    "description": "Trackunit Developer Hub",
    "url": "https://dev.trackunit.com/v3.0/"
  },
  "servers": [
    {
      "url": "https://iris.trackunit.com/api/organization/v1",
      "description": "Production"
    }
  ],
  "security": [{ "authorizationBearer": [] }],
  "paths": {
    "/accounts/{accountId}/connections": {
      "post": {
        "operationId": "addConnection",
        "parameters": [
          {
            "description": "Id of the account",
            "in": "path",
            "name": "accountId",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AddConnectionRequest" }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "*/*": {
                "schema": { "$ref": "#/components/schemas/ConnectedAccount" }
              }
            },
            "description": "OK"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConstraintViolationError"
                }
              }
            },
            "description": "Bad request"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Invalid or missing bearer token in Authorization header"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "User not allowed to make this request"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Resource not found"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Internal server error"
          }
        },
        "summary": "Add a connection to the account.",
        "tags": ["Connections"]
      }
    },
    "/accounts/{accountId}/connections/{connectedAccountId}": {
      "delete": {
        "operationId": "removeConnection",
        "parameters": [
          {
            "description": "Id of the account",
            "in": "path",
            "name": "accountId",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          },
          {
            "description": "Id of the connected account",
            "in": "path",
            "name": "connectedAccountId",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": { "description": "OK" },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConstraintViolationError"
                }
              }
            },
            "description": "Bad request"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Invalid or missing bearer token in Authorization header"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "User not allowed to make this request"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Resource not found"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Internal server error"
          }
        },
        "summary": "Remove the connection from the account.",
        "tags": ["Connections"]
      }
    },
    "/accounts/{accountId}/connections/{connectionAccountId}": {
      "get": {
        "operationId": "getConnectionByConnectedAccountId",
        "parameters": [
          {
            "description": "Id of the account",
            "in": "path",
            "name": "accountId",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          },
          {
            "description": "Id of the connected account",
            "in": "path",
            "name": "connectionAccountId",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "*/*": {
                "schema": { "$ref": "#/components/schemas/ConnectedAccount" }
              }
            },
            "description": "OK"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConstraintViolationError"
                }
              }
            },
            "description": "Bad request"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Invalid or missing bearer token in Authorization header"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "User not allowed to make this request"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Resource not found"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/DefaultError" }
              }
            },
            "description": "Internal server error"
          }
        },
        "summary": "Get the connection from the account by connected account ID.",
        "tags": ["Connections"]
      }
    }
  },
  "components": {
    "schemas": {
      "AddConnectionRequest": {
        "type": "object",
        "description": "Add connection request",
        "properties": {
          "allowSkippingRecipientShareConsent": {
            "type": "boolean",
            "default": false,
            "description": "Skip the requirement for recipient consent when sharing assets.\n\nThis is useful when the sender and recipient belongs to different organizations in the same hierarchy.\n"
          },
          "connectedAccountId": {
            "type": "string",
            "format": "uuid",
            "description": "Connected Account ID"
          }
        },
        "required": ["connectedAccountId"]
      },
      "ConnectedAccount": {
        "type": "object",
        "description": "Representation of a connections between two accounts in the same organization.\n\nA connection is a one-way relationship between two accounts. The connected account can see the account it is connected to, but not vice versa. For that, a separate connection must be created in the opposite direction.",
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "Account ID"
          },
          "allowSkippingRecipientShareConsent": {
            "type": "boolean",
            "description": "If true, the recipient will not be asked to accept the share of assets."
          },
          "connectedAccountId": {
            "type": "string",
            "format": "uuid",
            "description": "Connected Account ID"
          },
          "connectedAccountName": {
            "type": "string",
            "description": "Connected Account Name"
          }
        },
        "required": ["accountId", "connectedAccountId"]
      },
      "ConstraintViolationError": {
        "type": "object",
        "properties": {
          "code": {
            "type": ["string", "null"],
            "description": "Alphanumeric code (snake case) describing use case specific error"
          },
          "message": {
            "type": "string",
            "description": "Detailed description of error"
          },
          "properties": {
            "type": ["object", "null"],
            "additionalProperties": {},
            "description": "Additional properties to be included in the error response"
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "description": "HTTP status code"
          },
          "violations": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Violation" }
          }
        }
      },
      "DefaultError": {
        "type": "object",
        "properties": {
          "code": {
            "type": ["string", "null"],
            "description": "Alphanumeric code (snake case) describing use case specific error"
          },
          "message": {
            "type": "string",
            "description": "Detailed description of error"
          },
          "properties": {
            "type": ["object", "null"],
            "additionalProperties": {},
            "description": "Additional properties to be included in the error response"
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "description": "HTTP status code"
          }
        }
      },
      "Violation": {
        "type": "object",
        "properties": {
          "field": { "type": "string" },
          "message": { "type": "string" }
        }
      }
    },
    "securitySchemes": {
      "authorizationBearer": {
        "bearerFormat": "JWT",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "x-readme": { "explorer-enabled": true, "proxy-enabled": true }
}
