Skip to main content
BlueAI
Home/Guides/Response Format

Response Format

Standard envelope structure for API responses.

|

Overview

The BlueAI API uses a consistent response format across all endpoints. Standard envelopes are defined for single objects, lists, and errors, enabling uniform handling on the client side. All field names are returned in snake_case.

Single Object Response

Endpoints that return a single resource (e.g. GET /resource/:id, POST /resource) return the resource object directly. Each object includes id and object fields.

{
  "id": "deal_11111111111111111111111111111111",
  "object": "deal",
  "name": "Enterprise Contract",
  "amount": 1500000,
  "status": "open",
  "created_at": "2025-01-15T09:00:00Z",
  "updated_at": "2025-02-10T14:30:00Z"
}
FieldTypeDescription
idstringUnique identifier for the resource. Prefixed (e.g. deal_xxxx, inv_xxxx).
objectstringA string indicating the resource type (e.g. "deal", "invoice").
created_atstringWhen the resource was created (ISO 8601 format).
updated_atstringWhen the resource was last updated (ISO 8601 format).

List Response

List endpoints return a standard envelope containing a data array and pagination information.

{
  "object": "list",
  "data": [
    {
      "id": "deal_11111111111111111111111111111111",
      "object": "deal",
      "name": "Enterprise Contract",
      "amount": 1500000,
      "status": "open"
    },
    {
      "id": "deal_22222222222222222222222222222222",
      "object": "deal",
      "name": "Starter Plan",
      "amount": 300000,
      "status": "won"
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 50,
    "total": 142,
    "total_pages": 3
  }
}
FieldTypeDescription
objectstringAlways set to "list".
dataarrayAn array of resource objects.
paginationobjectAn object containing pagination metadata (page, per_page, total, total_pages).

Error Response

When an error occurs, a response containing an error object is returned. All errors follow a consistent structure.

{
  "error": {
    "type": "invalid_request_error",
    "code": "required",
    "message": "name is required",
    "param": "name"
  }
}

422 Unprocessable Entity:

{
  "error": {
    "type": "validation_error",
    "code": "invalid_parameters",
    "message": "One or more parameters are invalid",
    "errors": [
      {
        "field": "email",
        "code": "invalid_format",
        "message": "must be a valid email address"
      },
      {
        "field": "amount",
        "code": "out_of_range",
        "message": "must be greater than 0"
      }
    ]
  }
}
FieldTypeDescription
error.typestringThe error classification (e.g. invalid_request_error, authentication_error).
error.codestringA machine-readable error code (e.g. required, invalid_format).
error.messagestringA human-readable description of the error.
error.paramstring | nullThe parameter related to the error (if applicable).
error.errorsarray | nullAn array of validation error details (for 422 errors). Each element contains field, code, and message.

HTTP Status Codes

The API uses standard HTTP status codes to indicate the success or failure of a request.

StatusMeaningDescription
200OKThe request succeeded. The response body contains the resource.
201CreatedThe resource was successfully created. The response body contains the created resource.
204No ContentThe request succeeded but there is no content to return (e.g. DELETE operations).
400Bad RequestThe request body or parameters are invalid.
401UnauthorizedNo valid session or API key was provided.
403ForbiddenAuthenticated, but you do not have permission to perform this action.
404Not FoundThe requested resource does not exist.
409ConflictThe request conflicts with the current state (e.g. duplicate entry).
422Unprocessable EntityThe request is well-formed but contains semantic errors. The errors array contains per-field details.
429Too Many RequestsRate limit exceeded. See the Rate Limiting guide.
500Internal Server ErrorAn unexpected error occurred on the server. Please retry after a short wait.

Naming Conventions

All response fields are returned in snake_case. Request bodies should also be sent in snake_case. Do not use camelCase or PascalCase.

Correct (snake_case)

{
  "company_name": "Acme Corp",
  "created_at": "2025-01-15T09:00:00Z",
  "total_amount": 1500000,
  "is_active": true
}

Incorrect (camelCase)

{
  "companyName": "Acme Corp",
  "createdAt": "2025-01-15T09:00:00Z",
  "totalAmount": 1500000,
  "isActive": true
}

Example

# Fetch a single deal
curl https://api.blueai.jp/api/v1/crm/deals/deal_11111111111111111111111111111111 \
  -b cookies.txt
const res = await fetch(
  "https://api.blueai.jp/api/v1/crm/deals",
  { credentials: "include" },
);
const json = await res.json();

if (json.error) {
  // Error envelope
  console.error(json.error.type, json.error.message);
} else if (json.object === "list") {
  // List envelope
  for (const deal of json.data) {
    console.log(deal.id, deal.name);
  }
  console.log(`Total: ${json.pagination.total}`);
} else {
  // Single object
  console.log(json.id, json.name);
}