# Create a job

`POST /v4/records/jobs`

Creates a job record. Requires `jobs:write`. Create can set custom fields in the same format as PATCH.

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

Request body: application/json

Type: object

- `name` (required)
  Type: string
  
  Job name

- `company_id` (required)
  Type: string
  
  company ID to associate the job with

- `created_by` (optional)
  Type: string
  
  user ID of the record creator

- `assigned_to` (optional)
  Type: string
  
  user ID to assign the job to

- `assigned_by` (optional)
  Type: string
  
  user ID of the assigner

- `workflow_id` (optional)
  Type: string
  
  Job workflow ID to attach on creation. When omitted, the workspace default job workflow is used (see `GET /v4/workflows/defaults`); without a default the job gets no job workflow.

- `workflow_phase_id` (optional)
  Type: string
  
  Job-workflow phase ID to place the new job in. Requires workflow_id (the job workflow). Must belong to that workflow. When omitted, the job workflow's default sourcing phase is used if set; otherwise the job is attached to the job workflow without a phase. Does not apply to candidate_workflow_id.

- `candidate_workflow_id` (optional)
  Type: string
  
  Candidate workflow ID to attach on creation. When omitted, the workspace default job-candidate workflow is used (see `GET /v4/workflows/defaults`).

- `primary_document_id` (optional)
  Type: string
  
  file ID for the primary document

- `custom_fields` (optional)
  Type: object
  
  Object keyed by custom-field slug. Values may be strings, numbers, booleans, arrays, objects, or null. Image/file custom fields are read as `image:<sqid>` / `file:<sqid>` reference tokens and may be written with a linked object sqid or matching token.

Responses:

- 200: Job created

Content type: application/json

Type: object

Schema: [JobCreateResponse](https://docs.searchsoftware.nl/api/models/jobcreateresponse.md)

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

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

- 400: Invalid request 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"
  }
}
```

- 422: Validation error

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' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}'
```

### TypeScript

```typescript
const body = `{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}`;

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

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

### Python

```python
import requests

body = '''{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}'''

response = requests.post(
    'https://api.searchsoftware.nl/v4/records/jobs',
    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')
request = Net::HTTP::Post.new(uri)
request.body = <<-'BODY'.chomp
{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}
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(`{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}`)
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/records/jobs", 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'
{
  "name": "string",
  "company_id": "string",
  "created_by": "string",
  "assigned_to": "string",
  "assigned_by": "string",
  "workflow_id": "string",
  "workflow_phase_id": "string",
  "candidate_workflow_id": "string",
  "primary_document_id": "string",
  "custom_fields": {}
}
BODY;

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