# Update a location of a job

`PATCH /v4/records/jobs/{id}/locations/{location_id}`

Updates a location of the job. An omitted or `null` field keeps its current value; `""` clears it. If the body sets `country` or `country_code`, both country fields come from the body (the omitted one counts as `""`). `formatted` is rebuilt from the merged fields. `is_primary: true` makes this the only primary location; `false` clears the flag on this location only, leaving the job without a primary location. A location linked to more than one record cannot have its address edited (`409 LOCATION_SHARED`). Clearing every address field returns `422 EMPTY_LOCATION`. Requires `jobs:write`.

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

- `location_id` (path, string, required) - Location ID
  Type: string

Request body: application/json

Type: object

- `street` (optional)
  Type: string
  
  Street address; `""` clears it

- `city` (optional)
  Type: string
  
  City name

- `state` (optional)
  Type: string
  
  State, province or region

- `zip` (optional)
  Type: string
  
  Postal code

- `country` (optional)
  Type: string
  
  Country name

- `country_code` (optional)
  Type: string
  
  ISO 3166-1 alpha-2 country code

- `is_primary` (optional)
  Type: boolean
  
  Make this the primary location

Responses:

- 200: Location updated

Content type: application/json

Type: object

Schema: [LocationResponse](https://docs.searchsoftware.nl/api/models/locationresponse.md)

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

- `data` (required)
  Reference: [LocationObject](https://docs.searchsoftware.nl/api/models/locationobject.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

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 location 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: LOCATION_SHARED: the location is linked to other records

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: EMPTY_LOCATION or 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 PATCH 'https://api.searchsoftware.nl/v4/records/jobs/string/locations/string' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}'
```

### TypeScript

```typescript
const body = `{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}`;

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

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

### Python

```python
import requests

body = '''{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}'''

response = requests.patch(
    'https://api.searchsoftware.nl/v4/records/jobs/string/locations/string',
    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/locations/string')
request = Net::HTTP::Patch.new(uri)
request.body = <<-'BODY'.chomp
{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}
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(`{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}`)
  req, _ := http.NewRequest("PATCH", "https://api.searchsoftware.nl/v4/records/jobs/string/locations/string", 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'
{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}
BODY;

$ch = curl_init('https://api.searchsoftware.nl/v4/records/jobs/string/locations/string');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
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#"{
  "street": "string",
  "city": "string",
  "state": "string",
  "zip": "string",
  "country": "string",
  "country_code": "string",
  "is_primary": true
}"#;
    let response = client.patch("https://api.searchsoftware.nl/v4/records/jobs/string/locations/string")
        .body(body)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Content-Type", "application/json")
        .send()
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}
```
