# Find or create people and add them to a job

`POST /v4/records/jobs/{id}/candidates/intake`

Takes 1 to 20 people and adds each to the job as a candidate, finding the person first and creating them only when nobody matches. Requires `jobs:write` and `people:write`, and `notes:write` when an entry has a `note`; a missing scope fails the whole call before anything runs.

**Matching.** `person_id` given: that person. Otherwise the LinkedIn profile, then the email address; the first hit wins. LinkedIn profiles match on the profile slug, so the scheme, `www.` or a country subdomain, upper case, a trailing slash and query strings don't matter. A `linkedin_url` that is not a LinkedIn profile URL (a company page, a search) fails that entry.

**Review instead of guessing.** When nothing matched and `force_create` is not true, a person with exactly the same name (case-insensitive) makes the entry `needs_review` with reason `same_name` and up to five `possible_duplicates`; send it again with `person_id` or `force_create: true`. A LinkedIn match and an email match on two different people is `conflicting_matches`; a match in the trash is `in_trash`. A later entry with the LinkedIn profile or email of an earlier one, or with the same name as an earlier one when neither has a LinkedIn URL or email (and no `force_create`), is `duplicate_in_batch`. An email held by a trashed person is `in_trash`; an email held by two people is `conflicting_matches`.

**Creating.** A new person is created as by `POST /v4/records/people` (default people workflow, in its sourcing phase when one is set), with the LinkedIn URL saved as a bookmark (`https://www.linkedin.com/in/<slug>`). `company_name` without `company_id` is stored on the work history without a company record.

**Adding.** As by `POST /v4/records/jobs/{id}/candidates`. The `note` goes on the candidate (title "Sourcing note") only when the candidate was added in this call, so the same batch sent twice changes nothing the second time.

**Independent entries.** One entry's failure never stops the others and nothing is rolled back: a person created whose candidate link fails is `created` with `candidate: "failed"`. A matching person the caller can't see fails the entry ("A matching person exists outside your access.") and no second person is created. Per-entry problems (blank name, a field over its limit, a bad ID) fail that entry only.

`dry_run: true` runs the matching and writes nothing; outcomes read `would_create` and `would_match`. Each `results` entry has `index`, `name` and `outcome` (`created`, `matched`, `needs_review`, `duplicate_in_batch`, `failed`, `would_create`, `would_match`), plus, where they apply, `person_id`, `matched_by` (`linkedin`, `email`, `person_id`), `candidate` (`added`, `already_on_job`, `failed`), `candidate_id`, `note` (`added`, `none`, `failed`), `linkedin_saved`, `reason`, `possible_duplicates` and `error`. `created_by` is only accepted with an API key.

Authentication (security requirement alternatives):

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

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

Parameters:

- `id` (path, string, required) - Job ID
  Type: string

Request body: application/json

Type: object

- `people` (required)
  Type: array
  
  1 to 20 entries: `name` (required, at most 200 characters), and optionally `linkedin_url`, `email_address`, `phone_number`, `work_title`, `company_id`, `company_name`, `city`, `country_code` (two letters), `note` (at most 5,000 characters), `person_id`, `force_create`

- `phase_status_id` (optional)
  Type: string
  
  Starting phase ID from the job's candidate workflow, as for one candidate

- `dry_run` (optional)
  Type: boolean
  
  true reports what would happen and changes nothing

- `created_by` (optional)
  Type: string
  
  Acting user ID (API keys only)

Responses:

- 200: One report entry per input, in order

Content type: application/json

Type: object

Schema: [IntakeCandidatesResponse](https://docs.searchsoftware.nl/api/models/intakecandidatesresponse.md)

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

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

- 400: Invalid id or body, or an 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, or created_by is not the authorizing user

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

- 422: Not 1 to 20 people, or the phase is not in the job's candidate workflow

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/records/jobs/string/candidates/intake' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}'
```

### TypeScript

```typescript
const body = `{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}'''

response = requests.post(
    'https://api.searchsoftware.nl/v4/records/jobs/string/candidates/intake',
    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/records/jobs/string/candidates/intake')
request = Net::HTTP::Post.new(uri)
request.body = <<-'BODY'.chomp
{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "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(`{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}`)
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/records/jobs/string/candidates/intake", 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'
{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}
BODY;

$ch = curl_init('https://api.searchsoftware.nl/v4/records/jobs/string/candidates/intake');
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#"{
  "people": [],
  "phase_status_id": "string",
  "dry_run": true,
  "created_by": "string"
}"#;
    let response = client.post("https://api.searchsoftware.nl/v4/records/jobs/string/candidates/intake")
        .body(body)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Content-Type", "application/json")
        .send()
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}
```
