Result Management API
Below is the REST API documentation for managing Result data in your application. The Result entity stores user-generated outputs from a session or agent, and may contain encrypted fields (e.g., userName, userEmail, content).
Note: A TypeScript API client and example usage are available here:
1. Overview
The Result entity (based on the resultDTOSchema) stores session output data. Relevant endpoints allow you to:
- List all results (globally or per agent).
- Search/paginate results.
- Export results to a ZIP archive.
- Delete specific results.
Some fields (userName, userEmail, content) may be encrypted at the database level.
2. Data Schema & Fields
From the ResultDTO definition:
export const resultDTOSchema = z.object({ agentId: z.string().min(1), sessionId: z.string().min(1), userName: z.string().optional().nullable(), userEmail: z.string().optional().nullable(), content: z.string().optional().nullable(), format: z.string().optional().nullable(), createdAt: z.string().default(() => getCurrentTS()), updatedAt: z.string().default(() => getCurrentTS()), finalizedAt: z.string().optional().nullable(),});export type ResultDTO = z.infer<typeof resultDTOSchema>;agentId: String reference to the agent’s ID.sessionId: String reference to the session.userName&userEmail: User-provided info, often encrypted in the database.content: The session’s output or result text.format: A descriptor such asmarkdown,json, etc.createdAt&updatedAt: Default to the current timestamp.finalizedAt: Optional. If set, indicates no further modifications are expected.
3. Endpoints
3.1 GET /api/result
-
Description:
Returns all results across all agents and sessions, optionally filtered by query parameters (e.g.,sessionId,agentId, etc.). -
Example cURL:
Terminal window curl -X GET \"https://app.openagentsbuilder.com/api/result?sessionId=session-123" \-H "Authorization: Bearer <YOUR_API_KEY>" \-H "database-id-hash: <YOUR_DATABASE_ID_HASH>" -
Successful Response (HTTP
200):[{"agentId": "agent-123","sessionId": "session-123","userName": "Alice","userEmail": "[email protected]","content": "Some result content","format": "markdown","createdAt": "2025-03-21T10:00:00.000Z","updatedAt": "2025-03-21T11:00:00.000Z","finalizedAt": null},...] -
Error Response (e.g., 499, 500):
{"message": "Internal server error","status": 499}
Using the TypeScript Client
import { OpenAgentsBuilderClient } from "open-agents-builder-client";
const client = new OpenAgentsBuilderClient({ databaseIdHash: "YOUR_DATABASE_ID_HASH", apiKey: "YOUR_API_KEY"});
async function listAllResults() { const results = await client.result.listResults({ sessionId: "session-123" }); console.log("Results:", results);}3.2 DELETE /api/result/[id]
-
Description:
Deletes a specific Result bysessionId. The[id]in the URL is interpreted assessionId. -
Example cURL:
Terminal window curl -X DELETE \"https://app.openagentsbuilder.com/api/result/mySession123" \-H "Authorization: Bearer <YOUR_API_KEY>" \-H "database-id-hash: <YOUR_DATABASE_ID_HASH>" -
Successful Response (HTTP
200):{"message": "Data deleted successfully!","status": 200} -
Failure (HTTP
400):{"message": "Data not found!","status": 400}Or, if
[id]is missing or invalid:{"message": "Invalid request, no id provided within request url","status": 400}
Using the TypeScript Client
async function deleteResult(sessionId: string) { await client.result.deleteResult(sessionId); console.log(`Result for session ${sessionId} was deleted.`);}3.3 GET /api/agent/[id]/result
-
Description:
Lists paginated results for the agent identified by[id].
Accepts query params:limit(e.g.,10)offset(e.g.,0)orderBy("userName","userEmail","createdAt","updatedAt", default:"createdAt")query(partial string search inuserEmail,userName, orsessionId)
-
Example cURL:
Terminal window curl -X GET \"https://app.openagentsbuilder.com/api/agent/agent-123/result?limit=10&offset=0&orderBy=userName&query=alice" \-H "Authorization: Bearer <YOUR_API_KEY>" \-H "database-id-hash: <YOUR_DATABASE_ID_HASH>" -
Successful Response (HTTP
200, paginated):{"rows": [{"agentId": "agent-123","sessionId": "session-001","userName": "Alice","userEmail": "[email protected]","content": "Result content","format": "markdown","createdAt": "2025-03-21T10:00:00.000Z","updatedAt": "2025-03-21T11:00:00.000Z","finalizedAt": null},...],"total": 37,"limit": 10,"offset": 0,"orderBy": "userName","query": "alice"}rowsis an array ofResultDTOobjects.totalis the total matches for the query.limit,offset,orderBy,queryare echoed back for reference.
Using the TypeScript Client
async function listResultsForAgent(agentId: string) { // There's currently no specialized method for this route in the client, // but you can call it by passing custom query params to `listResults`. // If needed, you can add a new method to the ResultApi class for more direct usage. const results = await client.result.listResults({ agentId, limit: 10, offset: 0, orderBy: "userName", query: "alice" }); console.log(`Paginated results for agent ${agentId}:`, results);}You may need to extend the client or call
fetchdirectly if you want the exact paginated format (rows,total, etc.) returned byGET /api/agent/[id]/result. By default,listResultscalls/api/result, so partial adaptation might be required.
3.4 GET /api/agent/[id]/result/export
-
Description:
Exports all results (currently from all agents, though the code snippet also references[id]; you might adapt it) into a .zip archive with multiple files.
Each result is saved in a different format (.md,.json,.html) depending on itsformatfield.
Also creates anindex.md,index.html, andresults.jsoninside the ZIP. -
Notes:
- Uses
JSZipto package files in-memory. - If a result has
format: "markdown", we also produce a.mdfile and an.htmlversion (converted byshowdown). - If a result has
format: "json", we produce.jsonand.html(converted byjson2html). - Filenames are generated from a sanitized combination of
createdAt+sessionId. - The route triggers an audit log with
eventName: 'exportResults'.
- Uses
-
Example cURL:
Terminal window curl -X GET \"https://app.openagentsbuilder.com/api/agent/agent-123/result/export" \-H "Authorization: Bearer <YOUR_API_KEY>" \-H "database-id-hash: <YOUR_DATABASE_ID_HASH>" \-o result-export.zip -
Success Response (HTTP 200):
- Returns a
.zipfile. - The
Content-Typeisapplication/zip. - The response body is binary data.
- Returns a
Using the TypeScript Client
Currently, the result sub-client doesn’t implement a dedicated export method for handling ZIP responses. You can:
- Extend the ResultApi to include a
exportResultsmethod. - Use a direct
fetchapproach for the ZIP download.
Example (extending the client):
import { BaseClient } from "open-agents-builder-client";
class ExtendedResultApi extends BaseClient { public async exportResults(agentId: string): Promise<Blob> { const resp = await fetch(`${this.baseUrl}/api/agent/${agentId}/result/export`, { method: "GET", headers: { "Authorization": `Bearer ${this.apiKey}`, "database-id-hash": this.databaseIdHash } }); if (!resp.ok) { throw new Error(`Error exporting results: ${resp.statusText}`); } return resp.blob(); }}
// Usage in your code:const extendedResultApi = new ExtendedResultApi({ databaseIdHash: "YOUR_DATABASE_ID_HASH", apiKey: "YOUR_API_KEY"});
async function exportResultsForAgent(agentId: string) { const zipBlob = await extendedResultApi.exportResults(agentId); // Now handle the Blob (e.g., save to local filesystem in an Electron app, or upload elsewhere, etc.)}4. Encryption Details
- Fields like
userName,userEmail, andcontentare encrypted at rest using your storage key if provided in the server context. - You send plaintext to the server, which encrypts it before storing.
- When you fetch a result, the server decrypts it and returns plaintext.
- This ensures data at rest is securely encrypted.
5. Common Workflows
- List all results:
GET /api/result - Filter by session or agent:
GET /api/result?sessionId=...&agentId=... - Paginated listing for a specific agent:
GET /api/agent/[id]/result?limit=...&offset=... - Export all results for an agent:
GET /api/agent/[id]/result/export - Delete a result by session ID:
DELETE /api/result/[sessionId]
6. Example Calls
6.1 Listing All Results
curl -X GET \ "https://app.openagentsbuilder.com/api/result" \ -H "Authorization: Bearer <YOUR_API_KEY>" \ -H "database-id-hash: <YOUR_DATABASE_ID_HASH>"Returns [ ResultDTO, ... ].
Using the TypeScript Client
const allResults = await client.result.listResults();console.log("All results:", allResults);6.2 Deleting a Single Result
curl -X DELETE \ "https://app.openagentsbuilder.com/api/result/session-001" \ -H "Authorization: Bearer <YOUR_API_KEY>" \ -H "database-id-hash: <YOUR_DATABASE_ID_HASH>"Returns { "message": "Data deleted successfully!", "status": 200 } if found.
Using the TypeScript Client
await client.result.deleteResult("session-001");console.log("Result with session-001 deleted");6.3 Exporting Results (ZIP)
curl -X GET \ "https://app.openagentsbuilder.com/api/agent/agent-ABC/result/export" \ -H "Authorization: Bearer <YOUR_API_KEY>" \ -H "database-id-hash: <YOUR_DATABASE_ID_HASH>" \ -o agentABC-results.zipDownloadable .zip.
7. Error Handling
- 400 Bad Request: Missing or invalid parameters (e.g., invalid
[id]). - 401/403 Unauthorized/Forbidden: Invalid or missing credentials/headers.
- 499/500 Internal Error: Server issues (encryption/decryption failures, DB errors, etc.).
Each error typically includes a JSON body with a message and status.
8. Summary
Result records store user-submitted data (content) from sessions (sessionId) and reference a specific agent (agentId). You can:
- List results (
GET /api/resultorGET /api/agent/[id]/result). - Filter by query parameters (
sessionId,userEmail, etc.). - Export them to a
.zip(GET /api/agent/[id]/result/export). - Delete a result by session ID (
DELETE /api/result/[sessionId]).
Sensitive fields (userName, userEmail, content) are encrypted at rest. If you have additional requirements—like custom search parameters or file uploads—you can extend the existing endpoints or the official open-agents-builder-client TypeScript library accordingly.