# Answer every question of one form in a single write.

POST https://services.leadconnectorhq.com/ai-builder-api/projects/{projectId}/runs/{runId}/answers/batch

Records up to 12 answers in one run write and resumes the run once,
so a multi-question form does not resume the planner per answer.
Same per-answer rules as `POST …/answers` (records review approval
by `approve:<reviewId>` only, `decline:<reviewId>` declines,
anything else is a change request); `attachmentIds` are
ignored here. Project-scoped (`404` for another project's run);
`locationId` comes from the session, never from the body.

Idempotency: an answer whose `capId` and `correlationId` match the
recorded one is skipped; when every answer is such a duplicate
nothing is written and the run is not resumed again (still `202`).


## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `clientportal-ai.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | The API version. |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `projectId` | string | Yes | The project's id. |
| `runId` | string | Yes | The run's id. |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ai-builder-api/projects/{projectId}/runs/{runId}/answers/batch": {
      "post": {
        "summary": "Answer every question of one form in a single write.",
        "operationId": "answerEveryQuestionOfOneFormInASingleWrite",
        "description": "Records up to 12 answers in one run write and resumes the run once,\nso a multi-question form does not resume the planner per answer.\nSame per-answer rules as `POST …/answers` (records review approval\nby `approve:<reviewId>` only, `decline:<reviewId>` declines,\nanything else is a change request); `attachmentIds` are\nignored here. Project-scoped (`404` for another project's run);\n`locationId` comes from the session, never from the body.\n\nIdempotency: an answer whose `capId` and `correlationId` match the\nrecorded one is skipped; when every answer is such a duplicate\nnothing is written and the run is not resumed again (still `202`).\n",
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^prj_[A-Za-z0-9_-]+$"
            },
            "description": "The project's id.",
            "example": "prj_5f0c2a3e"
          },
          {
            "in": "path",
            "name": "runId",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^run_[A-Za-z0-9_-]+$"
            },
            "description": "The run's id.",
            "example": "run_8f3c2a91"
          },
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "The API version.",
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnswerQuestionsBatchRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Answers recorded; any awaiting agent resumes asynchronously.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnswerEveryQuestionOfOneFormInASingleWriteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Answers rejected by the run (empty `capId`/`value`, or the run is\nterminal). Code: `invalid_answer`.\n",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "404": {
            "description": "Run not found under this project (or at all).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "422": {
            "description": "Request validation failed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "clientportal-ai.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "A sub-account access token: a Marketplace app's OAuth token or a Private Integration Token."
      }
    },
    "schemas": {
      "AnswerQuestionsBatchRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "answers"
        ],
        "properties": {
          "answers": {
            "type": "array",
            "minItems": 1,
            "maxItems": 12,
            "description": "Each item is validated as `AnswerQuestionRequest`; `attachmentIds` are ignored on this route.",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "capId",
                "value"
              ],
              "description": "One answer to a run question. No `locationId`: tenancy comes from the\nsession. For a records review `value` is `approve:<reviewId>`\n(optionally `approve:<reviewId>:` + JSON with the `RoomChoice` keys\nand/or `images`: `{\"<change>:<fieldKey>\": [\"https://…\"]}` for the\nreview's image columns) or `decline:<reviewId>`; anything else is a change request. For a\n`RecordQuestionForm` `value` is the form's JSON.\n",
              "properties": {
                "capId": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64,
                  "description": "The question's id, e.g. `RunRecord.awaitingQuestion.capId` or a capability slug.",
                  "example": "cap_portal_modules"
                },
                "value": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64000,
                  "description": "The answer: the chosen choice's label, the typed text, or the JSON a form asks for.",
                  "example": "Courses"
                },
                "values": {
                  "type": "array",
                  "maxItems": 24,
                  "description": "Every slug chosen for a multi-select question; `value` carries the same choices as labels.",
                  "items": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "example": [
                    "courses",
                    "communities"
                  ]
                },
                "comments": {
                  "type": "string",
                  "maxLength": 4000,
                  "description": "Anything the creator added to the answer.",
                  "example": "Members should see their progress first."
                },
                "correlationId": {
                  "type": "string",
                  "maxLength": 64,
                  "description": "Dedupe key; a repeat with the same `capId` and `correlationId` is a no-op.",
                  "example": "ans_3f9a1c"
                },
                "attachmentIds": {
                  "type": "array",
                  "maxItems": 5,
                  "description": "Reference images for the answer (single-answer route only).",
                  "items": {
                    "type": "string"
                  },
                  "example": [
                    "att_1a2b3c"
                  ]
                }
              },
              "title": "AnswerQuestionRequest"
            },
            "example": [
              {
                "capId": "cap_portal_modules",
                "value": "Courses"
              }
            ]
          }
        },
        "title": "AnswerQuestionsBatchRequest"
      },
      "AnswerEveryQuestionOfOneFormInASingleWriteResponse": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              true
            ],
            "description": "The answers were accepted.",
            "example": true
          }
        }
      },
      "ApiError": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status",
          "code",
          "requestId"
        ],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri",
            "example": "about:blank",
            "description": "A URI identifying the kind of error."
          },
          "title": {
            "type": "string",
            "example": "Request validation failed",
            "description": "Short summary of the kind of error."
          },
          "status": {
            "type": "integer",
            "minimum": 400,
            "maximum": 599,
            "example": 422,
            "description": "The HTTP status code."
          },
          "detail": {
            "type": "string",
            "example": "One or more fields are invalid.",
            "description": "What went wrong with this request."
          },
          "instance": {
            "type": "string",
            "example": "/api/v1/runs",
            "description": "The request path that failed."
          },
          "code": {
            "type": "string",
            "example": "validation_error",
            "description": "Stable, machine-readable error code."
          },
          "requestId": {
            "type": "string",
            "example": "req_01HXQ8Z6J9K2",
            "description": "The request's id, for support."
          },
          "fieldErrors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "code",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string",
                  "example": "prompt",
                  "description": "The invalid field, as a dotted path."
                },
                "code": {
                  "type": "string",
                  "example": "required",
                  "description": "Machine-readable reason."
                },
                "message": {
                  "type": "string",
                  "example": "Prompt is required.",
                  "description": "Human-readable reason."
                }
              },
              "title": "FieldError"
            },
            "description": "One entry per invalid field, when the request body was invalid.",
            "example": [
              {
                "field": "name",
                "code": "too_long",
                "message": "name must be at most 120 characters"
              }
            ]
          }
        },
        "title": "ApiError"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "answers": [
    {
      "capId": "cap_portal_modules",
      "value": "Courses"
    }
  ]
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "answers": [
        {
          "capId": "cap_portal_modules",
          "value": "Courses"
        }
      ]
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/ai-builder-api/projects/{projectId}/runs/{runId}/answers/batch"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "answers": [
        {
            "capId": "cap_portal_modules",
            "value": "Courses"
        }
    ]
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "answers": [
    {
      "capId": "cap_portal_modules",
      "value": "Courses"
    }
  ]
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"answers\":[{\"capId\":\"cap_portal_modules\",\"value\":\"Courses\"}]}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch"
  payload := strings.NewReader(`{
  "answers": [
    {
      "capId": "cap_portal_modules",
      "value": "Courses"
    }
  ]
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "answers": [
    {
      "capId": "cap_portal_modules",
      "value": "Courses"
    }
  ]
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "answers": [
    {
      "capId": "cap_portal_modules",
      "value": "Courses"
    }
  ]
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ai-builder-api/projects/<projectId>/runs/<runId>/answers/batch' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
