# Upload a file to a job

`POST /v4/records/jobs/{id}/files/upload`

Uploads a file to a job using `multipart/form-data`. Include `file` as binary data and optional `primary_document` (`"true"` or `"false"`) to set `primary_document_id`.

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: multipart/form-data

Type: object

- `file` (required)
  Type: string, binary
  
  File binary data

- `primary_document` (optional)
  Type: string
  
  Set to "true" to update primary document

Responses:

- 200: File uploaded

Content type: application/json

Type: object

Schema: [UploadFileResponse](https://docs.searchsoftware.nl/api/models/uploadfileresponse.md)

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

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

- 400: Invalid id or no file provided

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_ID",
    "status_code": 400,
    "message": "Invalid id"
  }
}
```

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

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_ID",
    "status_code": 400,
    "message": "Invalid id"
  }
}
```

- 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: Record 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: 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/string/files/upload' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  --form-string 'primary_document=string'
```

### TypeScript

```typescript
const form = new FormData();
form.append('primary_document', 'string');
const response = await fetch('https://api.searchsoftware.nl/v4/records/jobs/string/files/upload', {
  method: 'POST',
  headers: {"Authorization":"Bearer YOUR_TOKEN"},
  body: form,
});
console.log(await response.text());
```

### Python

```python
import requests
from contextlib import ExitStack

with ExitStack() as stack:
    files = [
        ('primary_document', (None, 'string')),
    ]
    response = requests.request('POST', 'https://api.searchsoftware.nl/v4/records/jobs/string/files/upload', headers={"Authorization":"Bearer YOUR_TOKEN"}, files=files)
    print(response.text)
```

### Ruby

```ruby
require 'net/http'
uri = URI('https://api.searchsoftware.nl/v4/records/jobs/string/files/upload')
request = Net::HTTPGenericRequest.new('POST', true, true, uri.request_uri, {})
request['Authorization'] = 'Bearer YOUR_TOKEN'
request.set_form([['primary_document', 'string']], 'multipart/form-data')
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
puts response.body
```

### Go

```go
package main
import ("bytes"; "fmt"; "io"; "mime/multipart"; "net/http")
func main() {
  var body bytes.Buffer
  writer := multipart.NewWriter(&body)
  writer.WriteField("primary_document", "string")
  writer.Close()
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/records/jobs/string/files/upload", &body)
  req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
  req.Header.Set("Content-Type", writer.FormDataContentType())
  resp, err := http.DefaultClient.Do(req)
  if err != nil { panic(err) }
  defer resp.Body.Close()
  data, _ := io.ReadAll(resp.Body)
  fmt.Println(string(data))
}
```

### PHP

```php
<?php
$boundary = "sourcey-" . bin2hex(random_bytes(16));
$body = "";
$body .= "--" . $boundary . "\r\nContent-Disposition: form-data; name=\"primary_document\"\r\n\r\n" . 'string' . "\r\n";
$body .= "--" . $boundary . "--\r\n";
$ch = curl_init('https://api.searchsoftware.nl/v4/records/jobs/string/files/upload');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: multipart/form-data; boundary=" . $boundary, 'Authorization: Bearer YOUR_TOKEN']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
echo curl_exec($ch);
curl_close($ch);
```

### Rust

```rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let form = reqwest::multipart::Form::new()
    .text("primary_document", "string")
    ;
  let response = reqwest::Client::new().request(reqwest::Method::from_bytes(b"POST")?, "https://api.searchsoftware.nl/v4/records/jobs/string/files/upload")
    .header("Authorization", "Bearer YOUR_TOKEN")
    .multipart(form).send().await?;
  println!("{}", response.text().await?);
  Ok(())
}
```
