# Add a candidate to a job

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

Adds one person to a job as a candidate. Requires `jobs:write`.

**Starting phase.** Without `phase_status_id` the candidate starts in the job's candidate workflow (`candidate_workflow_id`), or in the workspace default `job_candidate` workflow (see `GET /v4/workflows/defaults`) when the job has none: that workflow's default sourcing phase, else its first phase. Without any workflow the candidate has no phase (`status_id` is `null`). An explicit `phase_status_id` must belong to that workflow, otherwise `422 INVALID_PHASE`. Adding writes the first entry of the candidate's phase history.

**No duplicates.** When the person is already a candidate on the job, nothing changes and the response has `added: false` with the existing candidate.

**Candidate type.** When the workspace has the person type `candidate` and the person doesn't have it yet, it is added. Other types stay as they are.

`created_by` is only accepted with an API key. With OAuth the candidate is always added by the authorizing user; another user answers `403 ACTOR_NOT_ALLOWED`. Use `PUT /v4/records/jobs/{id}/candidates/{person_id}/workflow-phase` to move the candidate later.

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

- `person_id` (required)
  Type: string
  
  Person ID to add as candidate

- `phase_status_id` (optional)
  Type: string
  
  Starting phase ID from the job's candidate workflow (default: the workflow's default sourcing phase, else its first phase)

- `created_by` (optional)
  Type: string
  
  User ID who added the candidate (API keys only)

Responses:

- 200: Candidate added or already on the job

Content type: application/json

Type: object

Schema: [AddJobCandidateResponse](https://docs.searchsoftware.nl/api/models/addjobcandidateresponse.md)

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

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

- 400: Invalid id or 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, 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 or person 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: 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' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "person_id": "string",
  "phase_status_id": "string",
  "created_by": "string"
}'
```

### TypeScript

```typescript
const body = `{
  "person_id": "string",
  "phase_status_id": "string",
  "created_by": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "person_id": "string",
  "phase_status_id": "string",
  "created_by": "string"
}'''

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

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