Skip to main content
{
  "status": "success",
  "message": "2 documents created successfully",
  "created_documents": [
    {
      "id": 123,
      "name": "contrato_servicio.pdf",
      "attachment_id": 456,
      "agent_id": 5,
      "owner_id": 1,
      "company_id": 2
    },
    {
      "id": 124,
      "name": "imagen_producto.jpg", 
      "attachment_id": 457,
      "agent_id": 5,
      "owner_id": 1,
      "company_id": 2
    }
  ],
  "total_created": 2,
  "agent_id": 5,
  "company_id": 2,
  "owner_id": 1
}

Create Documents

Create multiple documents in the Odoo system and associate them with a specific Quantum AI agent.

Endpoint

POST /api/v1/documents/create

Authentication

Bearer Token RequiredThe token must be valid for documents endpoint and POST method.
Authorization: Bearer <your_token_here>

Input Parameters

Body Parameters

owner_id
integer
required
Document owner ID
company_id
integer
required
Company ID
agent_id
integer
required
Quantum AI agent ID
documents
array
required
Array of documents to create. Each document must contain:

Responses

{
  "status": "success",
  "message": "2 documents created successfully",
  "created_documents": [
    {
      "id": 123,
      "name": "contrato_servicio.pdf",
      "attachment_id": 456,
      "agent_id": 5,
      "owner_id": 1,
      "company_id": 2
    },
    {
      "id": 124,
      "name": "imagen_producto.jpg", 
      "attachment_id": 457,
      "agent_id": 5,
      "owner_id": 1,
      "company_id": 2
    }
  ],
  "total_created": 2,
  "agent_id": 5,
  "company_id": 2,
  "owner_id": 1
}

Usage Examples

Example 1: Multiple documents

curl -X POST "https://www.cognivo.app/api/v1/documents/create" \
  -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "owner_id": 1,
    "company_id": 2,
    "agent_id": 5,
    "documents": [
      {
        "name": "contrato.pdf",
        "mimetype": "application/pdf",
        "base64": "JVBERi0xLjQKJcOkw7zDtsO4..."
      },
      {
        "name": "imagen.jpg",
        "mimetype": "image/jpeg", 
        "base64": "/9j/4AAQSkZJRgABAQEAYABgAAD..."
      }
    ]
  }'

Example 2: Simple text document

{
  "owner_id": 1,
  "company_id": 2,
  "agent_id": 5,
  "documents": [
    {
      "name": "notas.txt",
      "mimetype": "text/plain",
      "base64": "SG9sYSBtdW5kbyEgRXN0ZSBlcyB1biBhcmNoaXZvIGRlIHRleHRvLg=="
    }
  ]
}

Common MIME Types

  • PDF: application/pdf
  • Word: application/msword
  • Word (nuevo): application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Excel: application/vnd.ms-excel
  • Excel (nuevo): application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • JPEG: image/jpeg
  • PNG: image/png
  • GIF: image/gif
  • WebP: image/webp
  • Plain text: text/plain
  • ZIP: application/zip
  • JSON: application/json
  • XML: application/xml

Important Considerations

Validations

  • All required fields must be present
  • IDs must be valid integers
  • The documents array cannot be empty
  • Base64 content must be valid
  • Company, Agent and Owner must exist

Behavior

  • Individual processing per document
  • Automatic logging of errors and successes
  • Automatic linking to agent
  • Creation in attachment and document

Limits

  • Consider size limits for large files
  • No specific limit on number of documents
  • Possible timeouts on large requests

Troubleshooting

Solution: Verify that the base64 content is valid
import base64
try:
    base64.b64decode(base64_content)
    print("Valid base64")
except Exception as e:
    print(f"Invalid base64: {e}")
Solution: Verify that the agent exists and is active:
  • The agent must have active = True
  • The ID must be correct
Solution: Contact your system administrator to verify the owner ID and ensure proper user access permissions.
Version: 1.0
Last updated: 2025-01-13
I