Ir al contenido

Up to 500 writes of any resource in one call

POST
/v2/clients/{client_id}/batch
curl --request POST \
--url https://api-agent.manoflow.com/v2/clients/4e2a8c3d-1b9f-4e6a-8c7d-9f0a1b2c3d4e/batch \
--header 'Content-Type: application/json' \
--header 'x-kyto-key: <x-kyto-key>' \
--data '{ "items": [ { "resource": "contacts", "body": { "user_id": "+10000000042", "platform": "whatsapp", "lead_stage": "Lead Nuevo", "lead_stage_order": 1 } }, { "resource": "contacts", "body": { "user_id": "+10000000043", "platform": "whatsapp", "lead_score": "alto" } } ] }'

items (1-500) of {resource, body}: resource is contacts, conversations, bookings, orders or tickets, and body is exactly what that resource’s own POST takes. Items run in order, each in its own transaction, through the same code as the single route: one failing item undoes no other, and resending a batch is safe (every item is keyed by its own record id). The answer is 200 whenever the envelope can be read, with total, succeeded and one result per item: {index, status, result, id}, or {index, status, problem} with the item’s problem document (pointers relative to that item’s body; an item that is not an object, an unknown resource or a missing body point into /items/<i>). Text that cannot be stored (a NUL, a lone surrogate) fails only its item (invalid_text). An envelope that cannot be run is 422: items not a list (not_a_list), empty (empty_batch), over 500 (too_many_items), or an unknown top-level field; nested deeper than 64 levels is 400. The batch is one request for the rate limit and the 1 MiB limit.

client_id
required
string

The client the key belongs to (any other client is 403)

Example

4e2a8c3d-1b9f-4e6a-8c7d-9f0a1b2c3d4e

items: 1-500 writes.

Media typeapplication/json
BatchIn

Up to 500 writes, run in order.

object
items
required
Items
Array<object>
>= 1 items <= 500 items
BatchItemIn

One write: the resource and the body its own route takes. (Published in the OpenAPI; items are checked one by one below, so a bad item fails alone.)

object
resource
required
Resource
string
Allowed values: contacts conversations bookings orders tickets
body
required
Body
object
key
additional properties
any

Example

{
"items": [
{
"resource": "contacts",
"body": {
"user_id": "+10000000042",
"platform": "whatsapp",
"lead_stage": "Lead Nuevo",
"lead_stage_order": 1
}
},
{
"resource": "contacts",
"body": {
"user_id": "+10000000043",
"platform": "whatsapp",
"lead_score": "alto"
}
}
]
}

Every item answered on its own

Media typeapplication/json

Example

{
"total": 2,
"succeeded": 1,
"results": [
{
"index": 0,
"status": 200,
"result": "updated",
"id": "0c6f7a52-3d64-4b58-a1cd-5f0d1e2b9a10"
},
{
"index": 1,
"status": 422,
"problem": {
"type": "https://api-agent.manoflow.com/problems/validation-failed",
"title": "The request has invalid fields",
"status": 422,
"code": "validation_failed",
"detail": "1 field is invalid",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W",
"errors": [
{
"pointer": "/lead_score",
"code": "not_a_number",
"message": "must be a number"
}
]
}
}
]
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

The body is not valid JSON, or not a JSON object

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/invalid-json",
"title": "The body is not valid JSON",
"status": 400,
"code": "invalid_json",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

Missing, malformed, unknown or revoked key (one answer for all)

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/unauthorized",
"title": "Missing, malformed, unknown or revoked key",
"status": 401,
"code": "unauthorized",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

The key belongs to another client, or the client does not exist

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/forbidden",
"title": "The key does not belong to this client",
"status": 403,
"code": "forbidden",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

The body is over 1 MiB

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/payload-too-large",
"title": "The body is too large",
"status": 413,
"code": "payload_too_large",
"detail": "The limit is 1 MiB.",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

A write needs Content-Type: application/json

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/unsupported-media-type",
"title": "Content-Type must be application/json",
"status": 415,
"code": "unsupported_media_type",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

The envelope cannot be run: items not a list, empty (empty_batch) or over 500, or an unknown top-level field. Nothing was stored

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/validation-failed",
"title": "The request has invalid fields",
"status": 422,
"code": "validation_failed",
"detail": "1 field is invalid",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W",
"errors": [
{
"pointer": "/items",
"code": "too_many_items",
"message": "must hold 1 to 500 items"
}
]
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

The key made too many requests this minute (only when a limit is set); wait the Retry-After seconds

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/rate-limited",
"title": "Too many requests",
"status": 429,
"code": "rate_limited",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.

Unexpected error: quote the request_id

Media typeapplication/problem+json

Example

{
"type": "https://api-agent.manoflow.com/problems/internal-error",
"title": "Internal error",
"status": 500,
"code": "internal_error",
"request_id": "01J9ZK8Q4T7X2M5N6P3R1S0V9W"
}
X-Request-Id
string

The request’s id: the one sent, or a generated one. On every log line of the request; quote it when reporting a problem.