# Structurely Direct v2

## Overview

The Structurely API allows integrators to provide automation for their accounts. It offers various functionalities to streamline lead management, messaging, lead qualification conversations, and retrieval of metadata.

The Structurely API simplifies the integration process and removes the necessity to track additional fields in your system. It is specifically designed to utilize **your system's IDs** as internal keys, enabling you to seamlessly use IDs from your CRM or database as parameters, such as externalLeadId, and externalMessageId.

By utilizing this API, integrators can streamline their workflows, activate enhanced AI qualification conversations, and gain valuable insights into their accounts, leads, and conversations.

### Security

The Structurely API provides secure authentication and authorization mechanisms to ensure controlled access to its endpoints. The authentication system utilizes API tokens to secure interactions with the API.

Types of tokens and keys:

  
- bearer-access-token: Bearer JWT; **valid until deactivated**

**Note:** It is essential to keep your bearer-access-tokens secure and avoid sharing them with unauthorized parties to maintain the integrity and security of your Structurely API integration.

Version: `v3.35.20`

## Knowledge Bases

- [GET /api/direct/v2/knowledge-bases](/api/direct/v2/knowledge-bases/get.md)
- [POST /api/direct/v2/knowledge-bases](/api/direct/v2/knowledge-bases/post.md)
- [PATCH /api/direct/v2/knowledge-bases/{knowledgeBaseId}](/api/direct/v2/knowledge-bases/{knowledgeBaseId}/patch.md)
- [DELETE /api/direct/v2/knowledge-bases/{knowledgeBaseId}](/api/direct/v2/knowledge-bases/{knowledgeBaseId}/delete.md)

### GET /api/direct/v2/knowledge-bases

[GET /api/direct/v2/knowledge-bases](/api/direct/v2/knowledge-bases/get.md)

**Summary:** List knowledge bases

**Description:**

List knowledge bases for the authenticated account.

#### Responses

- `200`: Knowledge bases for the authenticated account
  - Schema: `KnowledgeBaseListResponse`
  ```json
  {
    "type": "object",
    "properties": {
      "knowledgeBases": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/KnowledgeBase"
        }
      }
    },
    "required": [
      "knowledgeBases"
    ]
  }
  ```
- `400`: Invalid request, check response message
  - Schema: `InvalidRequest`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "The parameter leadId must be provided"
      },
      "statusCode": {
        "type": "number",
        "example": 400
      }
    }
  }
  ```
- `401`: Request is not authorized
  - Schema: `NotAuthorized`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Access Token is not authorized"
      },
      "statusCode": {
        "type": "number",
        "example": 401
      }
    }
  }
  ```
- `500`: Internal server error, check response message
  - Schema: `InternalServerError`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Internal server error"
      },
      "statusCode": {
        "type": "number",
        "example": 500
      }
    }
  }
  ```

#### Security

- `bearer-access-token`

#### Example request

```bash
curl -sS -X GET 'https://client.structurely.com/api/direct/v2/knowledge-bases' \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $STRUCTURELY_API_TOKEN"
```

### POST /api/direct/v2/knowledge-bases

[POST /api/direct/v2/knowledge-bases](/api/direct/v2/knowledge-bases/post.md)

**Summary:** Create a knowledge base

**Description:**

Create a knowledge base for the authenticated account.

#### Request body

Knowledge base creation payload

Schema: `CreateKnowledgeBase`

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "customAnswers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBaseAnswer"
      }
    }
  },
  "required": [
    "name"
  ]
}
```

#### Responses

- `200`: The created knowledge base
  - Schema: `KnowledgeBase`
  ```json
  {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "format": "ObjectId"
      },
      "createdAt": {
        "type": "string",
        "format": "date-time"
      },
      "updatedAt": {
        "type": "string",
        "format": "date-time",
        "nullable": true
      },
      "name": {
        "type": "string"
      },
      "isEnabled": {
        "type": "boolean"
      },
      "type": {
        "type": "string"
      },
      "size": {
        "type": "integer"
      },
      "customAnswers": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/KnowledgeBaseAnswer"
        }
      }
    },
    "required": [
      "createdAt",
      "customAnswers",
      "id",
      "isEnabled",
      "name",
      "size",
      "type"
    ]
  }
  ```
- `400`: Invalid request, check response message
  - Schema: `InvalidRequest`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "The parameter leadId must be provided"
      },
      "statusCode": {
        "type": "number",
        "example": 400
      }
    }
  }
  ```
- `401`: Request is not authorized
  - Schema: `NotAuthorized`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Access Token is not authorized"
      },
      "statusCode": {
        "type": "number",
        "example": 401
      }
    }
  }
  ```
- `500`: Internal server error, check response message
  - Schema: `InternalServerError`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Internal server error"
      },
      "statusCode": {
        "type": "number",
        "example": 500
      }
    }
  }
  ```

#### Security

- `bearer-access-token`

#### Example request

```bash
curl -sS -X POST 'https://client.structurely.com/api/direct/v2/knowledge-bases' \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $STRUCTURELY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "string"
}'
```

### PATCH /api/direct/v2/knowledge-bases/{knowledgeBaseId}

[PATCH /api/direct/v2/knowledge-bases/{knowledgeBaseId}](/api/direct/v2/knowledge-bases/{knowledgeBaseId}/patch.md)

**Summary:** Update a knowledge base

**Description:**

Update a knowledge base for the authenticated account.

#### Parameters

- `knowledgeBaseId` (path, required: yes)
  - The Knowledge Base ID.
  - Schema:
    ```json
    {
      "oneOf": [
        {
          "format": "ObjectId",
          "type": "string"
        }
      ]
    }
    ```

#### Request body

Knowledge base patch payload

Schema: `PatchKnowledgeBase`

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "customAnswers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBaseAnswer"
      }
    }
  }
}
```

#### Responses

- `200`: The updated knowledge base
  - Schema: `KnowledgeBase`
  ```json
  {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "format": "ObjectId"
      },
      "createdAt": {
        "type": "string",
        "format": "date-time"
      },
      "updatedAt": {
        "type": "string",
        "format": "date-time",
        "nullable": true
      },
      "name": {
        "type": "string"
      },
      "isEnabled": {
        "type": "boolean"
      },
      "type": {
        "type": "string"
      },
      "size": {
        "type": "integer"
      },
      "customAnswers": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/KnowledgeBaseAnswer"
        }
      }
    },
    "required": [
      "createdAt",
      "customAnswers",
      "id",
      "isEnabled",
      "name",
      "size",
      "type"
    ]
  }
  ```
- `400`: Invalid request, check response message
  - Schema: `InvalidRequest`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "The parameter leadId must be provided"
      },
      "statusCode": {
        "type": "number",
        "example": 400
      }
    }
  }
  ```
- `401`: Request is not authorized
  - Schema: `NotAuthorized`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Access Token is not authorized"
      },
      "statusCode": {
        "type": "number",
        "example": 401
      }
    }
  }
  ```
- `404`: Resource was not found, check response message
  - Schema: `NotFound`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Lead not found"
      },
      "statusCode": {
        "type": "number",
        "example": 404
      }
    }
  }
  ```
- `500`: Internal server error, check response message
  - Schema: `InternalServerError`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Internal server error"
      },
      "statusCode": {
        "type": "number",
        "example": 500
      }
    }
  }
  ```

#### Security

- `bearer-access-token`

#### Example request

```bash
curl -sS -X PATCH 'https://client.structurely.com/api/direct/v2/knowledge-bases/{knowledgeBaseId}' \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $STRUCTURELY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### DELETE /api/direct/v2/knowledge-bases/{knowledgeBaseId}

[DELETE /api/direct/v2/knowledge-bases/{knowledgeBaseId}](/api/direct/v2/knowledge-bases/{knowledgeBaseId}/delete.md)

**Summary:** Delete a knowledge base

**Description:**

Delete a knowledge base for the authenticated account.

#### Parameters

- `knowledgeBaseId` (path, required: yes)
  - The Knowledge Base ID.
  - Schema:
    ```json
    {
      "oneOf": [
        {
          "format": "ObjectId",
          "type": "string"
        }
      ]
    }
    ```

#### Responses

- `200`: Knowledge base deletion result
  ```json
  {
    "example": "OK",
    "type": "string"
  }
  ```
- `400`: Invalid request, check response message
  - Schema: `InvalidRequest`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "The parameter leadId must be provided"
      },
      "statusCode": {
        "type": "number",
        "example": 400
      }
    }
  }
  ```
- `401`: Request is not authorized
  - Schema: `NotAuthorized`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Access Token is not authorized"
      },
      "statusCode": {
        "type": "number",
        "example": 401
      }
    }
  }
  ```
- `404`: Resource was not found, check response message
  - Schema: `NotFound`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Lead not found"
      },
      "statusCode": {
        "type": "number",
        "example": 404
      }
    }
  }
  ```
- `500`: Internal server error, check response message
  - Schema: `InternalServerError`
  ```json
  {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "A message describing the error",
        "example": "Internal server error"
      },
      "statusCode": {
        "type": "number",
        "example": 500
      }
    }
  }
  ```

#### Security

- `bearer-access-token`

#### Example request

```bash
curl -sS -X DELETE 'https://client.structurely.com/api/direct/v2/knowledge-bases/{knowledgeBaseId}' \
  -H "Accept: application/json" \
  -H "Authorization: Bearer $STRUCTURELY_API_TOKEN"
```

## Schemas

### `CreateKnowledgeBase`

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "customAnswers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBaseAnswer"
      }
    }
  },
  "required": [
    "name"
  ]
}
```

### `InternalServerError`

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "A message describing the error",
      "example": "Internal server error"
    },
    "statusCode": {
      "type": "number",
      "example": 500
    }
  }
}
```

### `InvalidRequest`

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "A message describing the error",
      "example": "The parameter leadId must be provided"
    },
    "statusCode": {
      "type": "number",
      "example": 400
    }
  }
}
```

### `KnowledgeBase`

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "ObjectId"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "nullable": true
    },
    "name": {
      "type": "string"
    },
    "isEnabled": {
      "type": "boolean"
    },
    "type": {
      "type": "string"
    },
    "size": {
      "type": "integer"
    },
    "customAnswers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBaseAnswer"
      }
    }
  },
  "required": [
    "createdAt",
    "customAnswers",
    "id",
    "isEnabled",
    "name",
    "size",
    "type"
  ]
}
```

### `KnowledgeBaseAnswer`

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "ObjectId",
      "nullable": true
    },
    "question": {
      "type": "string"
    },
    "answer": {
      "type": "string"
    }
  },
  "required": [
    "answer",
    "question"
  ]
}
```

### `KnowledgeBaseListResponse`

```json
{
  "type": "object",
  "properties": {
    "knowledgeBases": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBase"
      }
    }
  },
  "required": [
    "knowledgeBases"
  ]
}
```

### `NotAuthorized`

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "A message describing the error",
      "example": "Access Token is not authorized"
    },
    "statusCode": {
      "type": "number",
      "example": 401
    }
  }
}
```

### `NotFound`

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "A message describing the error",
      "example": "Lead not found"
    },
    "statusCode": {
      "type": "number",
      "example": 404
    }
  }
}
```

### `PatchKnowledgeBase`

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "customAnswers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/KnowledgeBaseAnswer"
      }
    }
  }
}
```

## Security

### `bearer-access-token`

```json
{
  "type": "http",
  "scheme": "bearer",
  "bearerFormat": "JWT"
}
```
