# Updating Data

### Update Records by Matching Field Values

This endpoint updates one or more records in a bloc by matching exact field-value pairs.

<mark style="color:green;">`POST`</mark> `https://example.mydomain.com/api/update-records-by-matching-values`

***

### Request Body

<table><thead><tr><th width="176.29296875">Name</th><th width="122.98828125">Type</th><th>Description</th></tr></thead><tbody><tr><td>blocId<mark style="color:red;">*</mark></td><td>string</td><td>The ID of the bloc to update. This may be a UUID or numeric ID depending on your instance.</td></tr><tr><td>fieldsToUpdate<mark style="color:red;">*</mark></td><td>object</td><td>Field slugs and the values to apply to matching records. Example: <code>{ "employee_name": "Jane Doe", "status": "Complete" }</code></td></tr><tr><td>searchItems<mark style="color:red;">*</mark></td><td>object</td><td>Field slugs and exact values used to find records to update. Example: <code>{ "employee_id": "5830" }</code></td></tr></tbody></table>

***

### Matching Behavior

* Matching uses exact key/value equality
* All matching records are updated
* If no records match, the request still succeeds and returns an empty array of updated IDs

***

### 200 Success Response

#### Records Updated

```json
{
  "updated_record_ids": [
    1223259
  ]
}
```

#### No Matching Records

```json
{
  "updated_record_ids": []
}
```

***

### Error Responses

#### 400 Bad Request

Returned when required request fields are missing.

```json
{
  "error": "Search Key/Value pairs or Bloc ID or Search Fields to update have not been provided"
}
```

Additional validation failures may return a `message` field instead of `error`, depending on the failure path.

#### 401 Unauthorized

```json
{
  "message": "You are not authorized to access this bloc"
}
```

***

### Example Requests

#### cURL

```bash
curl --request POST 'https://example.mydomain.com/api/update-records-by-matching-values' \
  --header 'Authorization: Bearer [AUTHTOKEN]' \
  --header 'Content-Type: application/json' \
  --data '{
    "blocId": "a1489634-4009-4cc0-8a65-9965f5a1bea7",
    "fieldsToUpdate": {
      "field_number_2": "Updated Value"
    },
    "searchItems": {
      "field_number_1": "Rafael"
    }
  }'
```

#### JavaScript

```javascript
const settings = {
  url: 'https://example.mydomain.com/api/update-records-by-matching-values',
  method: 'POST',
  timeout: 0,
  headers: {
    Authorization: 'Bearer [AUTHTOKEN]',
    'Content-Type': 'application/json'
  },
  data: JSON.stringify({
    blocId: 'a1489634-4009-4cc0-8a65-9965f5a1bea7',
    fieldsToUpdate: {
      field_number_2: 'Updated Value'
    },
    searchItems: {
      field_number_1: 'Rafael'
    }
  })
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
```

#### Node.js

```javascript
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://example.mydomain.com/api/update-records-by-matching-values',
  headers: {
    Authorization: 'Bearer [AUTHTOKEN]',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    blocId: 'a1489634-4009-4cc0-8a65-9965f5a1bea7',
    fieldsToUpdate: {
      field_number_2: 'Updated Value'
    },
    searchItems: {
      field_number_1: 'Rafael'
    }
  })
};

request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

#### Python

```python
import requests

url = "https://example.mydomain.com/api/update-records-by-matching-values"

payload = {
    "blocId": "a1489634-4009-4cc0-8a65-9965f5a1bea7",
    "fieldsToUpdate": {
        "field_number_2": "Updated Value"
    },
    "searchItems": {
        "field_number_1": "Rafael"
    }
}

headers = {
    "Authorization": "Bearer [AUTHTOKEN]",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```
