> This page is for API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.spreadspace.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.spreadspace.app/_mcp/server.

# Query extractions in bulk

POST https://api.spreadspace.app/api/borrowers/{borrower_id}/extractions/query-bulk
Content-Type: application/json

Runs the line item query across up to 200 documents at once, one call against your rate limit instead of a per-document fan-out. Send `document_ids`, 1 to 200 document ids (alphanumeric, at most 24 characters), plus the same optional `category`, `section`, `year`, `search`, and `loan_id` filters as the single query; `year` is a four-digit year from 2000 up to next year. Results come back grouped per document, in the order you sent the ids, capped at 500 line items per document. An id that doesn't resolve comes back with `not_found: true` instead of failing the request, and if the combined result would pass 100,000 line items, the response is truncated and carries an `X-Result-Truncated: true` header.

Requires the `extractions:read` scope. Rate limit: 200 requests per minute per key (the `api` lane).

Reference: https://docs.spreadspace.app/api/api-reference/extractions/query-extractions-bulk

## Authentication

- `Authorization` header (bearer token, required) — Bearer token. Use `ss_live_…` for live data or `ss_test_…` for the sandbox (test mode). See [Authentication](https://docs.spreadspace.app/api/authentication).

## Request

### Path parameters

- `borrower_id` (string, required) — The borrower's id.

### Headers

- `Idempotency-Key` (string, optional) — Idempotency token. Retries that reuse the key within 24h replay the original response. Up to 255 characters; a UUID is typical. See [Idempotency](https://docs.spreadspace.app/api/idempotency).
- `SpreadSpace-Version` (string, optional) — Pin the API version, e.g. `2026-10-07`. Omit to get the latest. See [Versioning](https://docs.spreadspace.app/api/versioning).

### Body (application/json)

This endpoint expects a QueryExtractionsBulkRequest.

- `document_ids` (list of string, required) — 1 to 200 document ids (24-character ids).
- `loan_id` (string, optional, nullable)
- `category` (string, optional, nullable)
- `section` (string, optional, nullable)
- `year` (integer, optional, nullable) — Four-digit fiscal year, 2000 up to next year.
- `search` (string, optional, nullable)

## Response

### 200

OK

- `borrower_id` (string, required)
- `documents` (list of DocumentExtractionResult, required)
- `total_documents` (integer, required)
- `total_line_items` (integer, required)
- `total_amount` (string, required) — Monetary amount as a decimal string with exactly two decimal places.

## Errors

### 400 Bad Request Error

Bad request: validation failed, the cursor is malformed, or the API version is unknown.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 401 Unauthorized Error

Unauthorized: the bearer token or API key is missing or invalid.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 402 Payment Required Error

Payment required: the standard error envelope with `type` `subscription_required` when the workspace has no active or trialing subscription, or `billing_required` where a plan entitlement applies.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 403 Forbidden Error

Forbidden: authentication succeeded but the caller is not permitted to perform this action, for example an API key missing the required scope, an embed session reaching a loan it was not minted for, or a feature outside the workspace's plan.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 404 Not Found Error

Not found: the resource does not exist or is not visible to the calling tenant.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 409 Conflict Error

Conflict: a version mismatch, where `details.current_version` carries the version the resource is actually at so the client can reload and re-apply, or an idempotency key reused with a different request body.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 429 Too Many Requests Error

Too many requests: the rate limit was hit, or an idempotency-key replay is still in progress.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

### 500 Internal Server Error

Internal server error: an unexpected failure. Quote the `request_id` in support tickets. A mutation sent with an `Idempotency-Key` replays this fault under that key rather than re-running; confirm the resource state before resending with a new key.

- `error` (ApiErrorBody, required) — Inner body of the canonical API error envelope.

## Types

### DocumentExtractionResult

- `document_id` (string, required)
- `items` (list of LineItemSummary, required)
- `total` (string, required) — Monetary amount as a decimal string with exactly two decimal places.
- `not_found` (boolean, required)

### ApiErrorBody

Inner body of the canonical API error envelope.

- `type` (string, required) — Stable error type identifier. Pattern-match on this value, not the human-readable message.
- `message` (string, required) — Human-readable error message. Subject to wording changes; do not parse.
- `request_id` (string, optional, nullable) — Per-request correlation ID (matches `X-Request-ID` response header). Quote in support tickets.
- `details` (map from string to string, optional, nullable) — Structured detail. Some error types populate documented keys in every environment: a version conflict (409) carries `current_version`, the version the resource is actually at, so the client can reload and re-apply. Free-form diagnostic detail beyond those keys appears in development environments only. An `insufficient_credits` 402 carries `balance_usd`, `reserved_usd`, `in_flight_docs`, `incoming_docs` and `per_doc_reservation_usd` as decimal strings.

### LineItemSummary

- `section` (string, required)
- `item_name` (string, required)
- `amount` (string, required) — Monetary amount as a decimal string with exactly two decimal places.
- `group_name` (string, optional, nullable)
- `standard_category` (string, optional, nullable)
- `period` (string, optional, nullable)
- `fiscal_year` (integer, optional, nullable)
- `aging_bucket` (string, optional, nullable)

## Examples

**Request**

```json
{
  "document_ids": [
    "9f8b7c6a5d4e3f2a1b0c9d8e"
  ]
}
```

**Response**

```json
{
  "borrower_id": "9f8e7d6c5b4a3210a1b2c3d4",
  "documents": [
    {
      "document_id": "9a7c6b5d4e3f210987654321",
      "items": [
        {
          "section": "Income",
          "item_name": "Gross receipts or sales",
          "amount": "2450000.00",
          "group_name": null,
          "standard_category": "revenue",
          "period": "2023",
          "fiscal_year": 2023,
          "aging_bucket": null
        },
        {
          "section": "Expenses",
          "item_name": "Rent",
          "amount": "96000.00",
          "group_name": "Operating expenses",
          "standard_category": "rent_expense",
          "period": "2023",
          "fiscal_year": 2023,
          "aging_bucket": null
        }
      ],
      "total": "2546000.00",
      "not_found": false
    },
    {
      "document_id": "1b2c3d4e5f67890123456789",
      "items": [],
      "total": "0.00",
      "not_found": true
    }
  ],
  "total_documents": 2,
  "total_line_items": 2,
  "total_amount": "2546000.00"
}
```

**SDK Code**

```python
import requests

url = "https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk"

payload = { "document_ids": ["9f8b7c6a5d4e3f2a1b0c9d8e"] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"document_ids":["9f8b7c6a5d4e3f2a1b0c9d8e"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk"

	payload := strings.NewReader("{\n  \"document_ids\": [\n    \"9f8b7c6a5d4e3f2a1b0c9d8e\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"document_ids\": [\n    \"9f8b7c6a5d4e3f2a1b0c9d8e\"\n  ]\n}"

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

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"document_ids\": [\n    \"9f8b7c6a5d4e3f2a1b0c9d8e\"\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk', [
  'body' => '{
  "document_ids": [
    "9f8b7c6a5d4e3f2a1b0c9d8e"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"document_ids\": [\n    \"9f8b7c6a5d4e3f2a1b0c9d8e\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["document_ids": ["9f8b7c6a5d4e3f2a1b0c9d8e"]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.spreadspace.app/api/borrowers/9f8e7d6c5b4a3210a1b2c3d4/extractions/query-bulk")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```