# Apply a bulk update

`POST /v4/bulk-updates/{plan_id}/apply`

Applies the plan to its next records: at most 25, and at most 15 seconds, per call. Call it again while `remaining` is above 0. `confirm_total` must be the plan's `total` (422 `CONFIRMATION_MISMATCH`; the error doesn't repeat the number: read it with `GET /v4/bulk-updates/{plan_id}`). Each record is checked again first: one that is gone or no longer visible is skipped (`not_found`), one already in the target is skipped (`unchanged`), a trashed one is skipped for every change but `status` (`in_trash`), and a person on `permno` keeps that GDPR status (`gdpr_locked`). A failure never stops the chunk. `results` lists this call's records. Two calls at once on one plan: one answers 409 `PLAN_BUSY`. Once started, a plan lapses 24 hours later. A completed plan answers its totals again. 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

Parameters:

- `plan_id` (path, string, required) - Plan ID from `POST /v4/bulk-updates`
  Type: string

Request body: application/json

Type: object

- `confirm_total` (required)
  Type: integer
  
  The plan's total, as the preview returned it

Responses:

- 200: Chunk applied

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

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"
  }
}
```

- 404: Plan not found

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "NOT_FOUND",
    "status_code": 404,
    "message": "Record not found"
  }
}
```

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

```json
{
  "status": "error",
  "error": {
    "code": "NOT_FOUND",
    "status_code": 404,
    "message": "Record not found"
  }
}
```

- 409: Plan busy or cancelled

Content type: application/json

Type: object

Schema: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md)

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

- `error` (required)
  Reference: [ErrorBody](https://docs.searchsoftware.nl/api/models/errorbody.md); Type: object

- 410: Plan expired

Content type: application/json

Type: object

Schema: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md)

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

- `error` (required)
  Reference: [ErrorBody](https://docs.searchsoftware.nl/api/models/errorbody.md); Type: object

- 422: confirm_total is not the plan's total

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/string/apply' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "confirm_total": 0
}'
```

### TypeScript

```typescript
const body = `{
  "confirm_total": 0
}`;

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

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

### Python

```python
import requests

body = '''{
  "confirm_total": 0
}'''

response = requests.post(
    'https://api.searchsoftware.nl/v4/bulk-updates/string/apply',
    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/string/apply')
request = Net::HTTP::Post.new(uri)
request.body = <<-'BODY'.chomp
{
  "confirm_total": 0
}
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(`{
  "confirm_total": 0
}`)
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/bulk-updates/string/apply", 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'
{
  "confirm_total": 0
}
BODY;

$ch = curl_init('https://api.searchsoftware.nl/v4/bulk-updates/string/apply');
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#"{
  "confirm_total": 0
}"#;
    let response = client.post("https://api.searchsoftware.nl/v4/bulk-updates/string/apply")
        .body(body)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Content-Type", "application/json")
        .send()
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}
```
