# Preview a bulk update

`POST /v4/bulk-updates`

Selects records and stores their IDs in a plan with one change; nothing changes yet. The selection is either `records` (1 to 1,000 IDs) or a search with the body of `POST /v4/records/{plural_slug}/search` without paging (`query`, `filters`, `near`, `document_query`); a search that selects everything is refused (422 `SELECTION_REQUIRED`). A plan holds at most 1,000 records, the oldest first: with more matches it says `capped: true` and the real `matched`. Permanently deleted and hidden records are never in a plan, and a status change leaves out the records already in the target. `change.kind` is `status` (`normal` or `delete`, the trash), `workflow_phase` (`workflow_id`, `phase_status_id`, optional `note`), `assignee` (`user_id`, or null to unassign) or `gdpr_status` (people only: `permok`, `permreq`, `permno`, `novalue`; from AI apps only with the workspace setting, 403 `GDPR_WRITE_DISABLED`). An unknown workflow, a phase of another workflow or an inactive user fails here (422 `INVALID_CHANGE`). A `document_query` that matches more than 200 records is refused (422 `DOCUMENT_MATCHES_TRUNCATED`): a plan never holds part of a document selection. The answer has `plan_id`, `total`, `matched`, `capped` and a `sample` of ten records with the `current` value of the attribute the change touches. The plan lapses 30 minutes after preview unless applied. With OAuth the plan belongs to the authorizing user; an API key names `created_by` (422 `ACTOR_REQUIRED` without it). Requires the object's write scope: `people:write`, `companies:write` or `jobs:write` (for an existing plan, the scope of the plan's object).

Authentication (security requirement alternatives):

```json
[
  {
    "bearer_auth": []
  },
  {
    "oauth2_auth": []
  },
  {
    "apikey_auth": []
  }
]
```

- bearer_auth: http (bearer). API key or OAuth access token in Authorization header
- oauth2_auth: oauth2. OAuth authorization code flow with mandatory S256 PKCE.
- apikey_auth: apiKey, query api_key. API key in query string

Request body: application/json

Type: object

- `object` (required)
  Type: string
  
  people, companies or jobs

- `query` (optional)
  Type: string
  
  Keywords, as in the record search

- `filters` (optional)
  Type: array
  
  Filter groups, as in the record search

- `near` (optional)
  Type: object
  
  A radius around a place or point, as in the record search

- `document_query` (optional)
  Type: string
  
  A keyword in the CV or main document, as in the record search. At most 200 matching records; more is refused (422 DOCUMENT_MATCHES_TRUNCATED).

- `records` (optional)
  Type: array
  
  Record IDs in place of a search, 1 to 1,000

- `change` (required)
  Type: object
  
  `kind` plus that kind's fields

- `created_by` (optional)
  Type: string
  
  API keys only: the acting user's ID

Responses:

- 200: Plan prepared

Content type: application/json

Type: object

Schema: [BulkUpdatePlanResponse](https://docs.searchsoftware.nl/api/models/bulkupdateplanresponse.md)

- `status` (required)
  Type: string
  
  enum: ["ok"]
  
  Example:
  
  ```json
  "ok"
  ```

- `data` (required)
  Reference: [BulkUpdatePlan](https://docs.searchsoftware.nl/api/models/bulkupdateplan.md); Type: object

- 400: Invalid body or unknown key

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_BODY",
    "status_code": 400,
    "message": "Invalid request body"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_BODY",
    "status_code": 400,
    "message": "Invalid request body"
  }
}
```

- 401: Invalid API key

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_API_KEY",
    "status_code": 401,
    "message": "Invalid API key"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_API_KEY",
    "status_code": 401,
    "message": "Invalid API key"
  }
}
```

- 403: Insufficient scope

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "FORBIDDEN",
    "status_code": 403,
    "message": "Insufficient scope"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "FORBIDDEN",
    "status_code": 403,
    "message": "Insufficient scope"
  }
}
```

- 422: Invalid object, change or selection, no matching records, no acting user, or a document_query matching more than 200 records (DOCUMENT_MATCHES_TRUNCATED)

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "VALIDATION_FAILED",
    "status_code": 422,
    "message": "Validation failed"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "VALIDATION_FAILED",
    "status_code": 422,
    "message": "Validation failed"
  }
}
```

- 500: Internal server error

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INTERNAL_ERROR",
    "status_code": 500,
    "message": "Internal server error"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INTERNAL_ERROR",
    "status_code": 500,
    "message": "Internal server error"
  }
}
```

## Examples

### cURL

```bash
curl -X POST 'https://api.searchsoftware.nl/v4/bulk-updates' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}'
```

### TypeScript

```typescript
const body = `{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}`;

const response = await fetch('https://api.searchsoftware.nl/v4/bulk-updates', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}'''

response = requests.post(
    'https://api.searchsoftware.nl/v4/bulk-updates',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```

### Ruby

```ruby
require 'net/http'
require 'json'

uri = URI('https://api.searchsoftware.nl/v4/bulk-updates')
request = Net::HTTP::Post.new(uri)
request.body = <<-'BODY'.chomp
{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}
BODY
request['Authorization'] = 'Bearer YOUR_TOKEN'
request['Content-Type'] = 'application/json'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
data = JSON.parse(response.body)
```

### Go

```go
package main

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

func main() {
  body := strings.NewReader(`{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}`)
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/bulk-updates", body)
  req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
  req.Header.Set("Content-Type", "application/json")
  resp, _ := http.DefaultClient.Do(req)
  defer resp.Body.Close()
  data, _ := io.ReadAll(resp.Body)
  fmt.Println(string(data))
}
```

### PHP

```php
<?php
$body = <<<'BODY'
{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}
BODY;

$ch = curl_init('https://api.searchsoftware.nl/v4/bulk-updates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer YOUR_TOKEN', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

### Rust

```rust
use reqwest;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = reqwest::Client::new();
    let body = r#"{
  "object": "string",
  "query": "string",
  "filters": [],
  "near": {},
  "document_query": "string",
  "records": [],
  "change": {},
  "created_by": "string"
}"#;
    let response = client.post("https://api.searchsoftware.nl/v4/bulk-updates")
        .body(body)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Content-Type", "application/json")
        .send()
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}
```
