Email Classification
The purpose of this flow is to provide a step-by-step guide to integrating the Blockbrain API for automated email classification.
1. Introduction
The intended use case is to classify incoming emails according to a predefined rule set. The classification logic is configured in the Blockbrain UI and can be accessed via the API for automation purposes.
All functionality available in the UI is also exposed through the API. The UI should be used to set up the classification bot and its prompt, while the API should be used to implement automated or large-scale workflows. The complete Blockbrain API documentation is provided here: https://blocky.theblockbrain.ai/docs
Before proceeding with the workflow, ensure you have:
Configured your Email Classification bot.
Defined and saved the classification ruleset in the E-Mail Classification prompt in the prompt library.
Selected the appropriate LLM model in the bot settings (for example GPT 5).
Retrieved your
bot_id, agentTaskId as described in Section 4 of this guide.
2. API Basic Workflow
The process for classifying a single email consists of four main steps. It is strongly recommended to create a separate Data Room for each Email to maintain isolation between classifications and enable parallel processing.
Step 1 β Create Data Room
This operation creates a new conversation (Data Room) associated with your Email Classification bot.
Endpoint: POST /cortex/active-bot/{bot_id}/convo
API Reference: Create Data Room β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/active-bot/687e4c1b04e932e500e46c52/convo
Example request body
Example response body
The response will contain a convoId that identifies this data room. This convoId is needed for the following steps.
Step 2 β Submit User (Email) Content
This operation sends the email text to the classification bot for processing.
Endpoint: POST /cortex/completions/v2/user-input
API Reference: Add User Messages β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/completions/v2/user-input
Example request body
If enableStreaming is enabled, responses are returned token by token using Streaming. In that case, you may concatenate all returned new_token objects to form the final output.
Step 3 β Retrieve Classification Result
This operation retrieves the message detail through the messageId obtained as response in the previous step.
Endpoint: GET /cortex/message/{message_id}
API Reference: Get Message Detail - API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/message/{message_id}
The classification result is the content of the response body, while the original sent message (E-Mail text) is targetText.
Alternatively you may get the complete message list
This operation retrieves the complete list of messages for a given conversation (convo_id).
Endpoint: POST /cortex/message/list
API Reference: Get Message List β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/message/list
Example request body
Step 4 β Delete Data Room
This operation deletes the conversation (Data Room) to free resources and maintain a clean state.
Endpoint: DELETE /cortex/conversation/{convo_id}
API Reference: Delete Conversation β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/conversation/68a7277b804f80bd70b1c43
3. Best Practices
Create a new Data Room for each incoming email to avoid carrying over context from previous messages.
Use the prompt library to store classification prompts and ensure consistent use across UI and API.
Maintain separate API calls for each classification to keep workflows easy to trace.
4. Retrieving Necessary IDs
The following IDs are required for the API calls described in the workflow above.
Retrieving bot_id from the UI
bot_id from the UILog in to Blockbrain and navigate to the Bot Creator in the UI.
Select your Email Classification Bot. The bot details will include a field named
bot ID. This is the value used in the/cortex/active-bot/{bot_id}/convocall.

Generating sessionId
You will need to generate a random UUID from your client side and send it along with the request. You may use this sessionId for multiple API calls as shown in the workflow above and neednβt generate new sessionId for each.
Tip: You can also obtain a valid sessionId by logging in through the UI and then capturing it from the API requests in your browserβs developer tools. This is useful during initial testing because you can use that value directly when experimenting with API calls.
Retrieving agentTaskId
To access the complete list of agent tasks for your bot call:
GET /cortex/active-bot/{bot_id} (API Reference:Get Active Bot Details β API Documentation ). The response will contain an array of Agent Tasks associated with the bot, including their id, name, and prompt details.
Tip: You can also obtain an agentTaskId by logging in through the UI and then capturing it from the API requests in your browserβs developer tools. The agentTaskId is unique for each selected prompt from the prompt library.
5. Working with Attachments
The best practice for integrating attachments into the conversation context is to upload the email attachment to the dataroom.
Endpoint: POST /cortex/conversation/{convo_id}/attachment
API Reference: Direct Upload Attachment β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/conversation/{convo_id}/attachment
Example request body
Example Response
Wait for Upload Completion
Before proceeding to the next workflow step, ensure the attachment(s) are successfully uploaded. The expected response structure is identical to the upload output. Poll until calculatedStatus = "SUCCESS" before continuing.
Endpoint: GET /cortex/conversation/{convo_id}/attachment
API Reference: Get Conversation Attachments β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/conversation/{convo_id}/attachment
Example response body
6. Working with Workflows
Best practice is to create a workflow in the UI and then trigger it via API. Workflows can also be created or updated programmatically using API calls such as create workflow step or update workflow step (Create & Update Workflow Step β API Documentation).
To execute a complete workflow via API
Endpoint: POST /cortex/executor
API Reference: Create Action Executor Workflow β API Documentation
Example request URL
https://blocky.theblockbrain.ai/cortex/executor
Example request body
Example response body
Recommendation: Retrieve the workflowId from the UI (Developer Settings) rather than a dedicated API call. Best practice is to set the workflow to autopilot in the UI, so that all steps are automatically executed in sequence via API workflow. Select in this case action type βcontinue_to_endβ.
Workflow modes
Autopilot: Executes all steps automatically
Human in the Loop: Requires user interaction between steps
Change Workflow Mode in the UI
In a data room, select workflows in the right side panel (Settings β Bot Settings β Workflows)
Select the workflow on the left-hand side
At the bottom-left of the workflow canvas, click Execution Mode and choose Autopilot.
Click Save

Get Detail Run Task ID
To retrieve the Step Id of each workflow step, use the Get Detail Run Task ID endpoint.
Endpoint: GET cortex/executor/get-detail-run-task-by-id/{run_task_id}
API Reference: Get Detail Run Task Id - API Documentation
Example Request URL
https://blocky.theblockbrain.ai/cortex/executor/get-detail-run-task-by-id/{run_task_id}
Example request body
Retrieve Results of a Specific Workflow Step
Endpoint: GET
/cortex/executor/get-workflow-step-output/{run_task_id}/{step_id}API Reference: Get Workflow Step Output - API Dcoumentation
Example Request URL
https://blocky.theblockbrain.ai/cortex/executor/get-workflow-step-output/{run_task_id}/{step_id}
The results of each step are found in the responseMessage - content field.
Example response body
Further useful API Endpoints for working with Workflows
Save Workflow Output to Dataroom:
Endpoint: POST
/cortex/executor/save-run-task-outputAPI Reference: Save Run Task Output - API Documentation
Example Request URL
https://blocky.theblockbrain.ai/cortex/executor/save-workflow-step-output/{step_id}
Example request body
The output can be saved in multiple formats; refer to the documentation for supported formats.
Run Workflow Step with Action:
This can be used to run individual steps or run workflows with human-in-the-loop, so that the whole workflow isnβt automatically executed.
Endpoint: POST
cortex/executor/run-step-with-actionAPI Reference: Run Workflow Step in Action - API Documentation
Example Request URL
https://blocky.theblockbrain.ai/cortex/executor/run-step-with-action
Example request Body
Last updated
Was this helpful?