> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmembrane.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update

The `update` method modifies an existing record in the collection.

## Configuration Example

```yaml theme={null}
# spec.yml
name: Collection Name
methods:
  update:
    fields:
      - email
      - firstName
      - lastName
    excludedFields:
      - id
      - createdAt
    parametersSchema:
      type: object
      properties:
        partial:
          type: boolean
          default: true
          description: Allow partial updates
```

### Configuration Options

* **`fields`** (array): Whitelist of fields that can be updated
* **`excludedFields`** (array): Fields that cannot be updated

## Implementation Examples

### REST API Mapping Implementation (Recommended)

**File:** `update.rest.yml`

```yaml theme={null}
path: /contacts/{id}
method: PUT
requestMapping:
  pathParameters:
    id: { $var: $.id }
  body: { $var: $.fields }
responseMapping:
  id: |
    {
      $or: [
        { $string: { $var: response.data.contact_id } },
        { $var: $.id }
      ]
    }
```

### Operation Mapping Implementation

**File:** `update.yml`

```yaml theme={null}
implementationType: operation-mapping
mapping:
  operationKey: updateContact
  inputMapping:
    contactId: { $var: $.id }
    contactData: { $var: $.fields }
    updateOptions:
      partial: { $var: $.parameters.partial }
  outputMapping:
    id: { $string: { $var: result.contactId } }
```

### JavaScript Implementation

**File:** `update.js`

```javascript theme={null}
export default async function update({ externalApiClient, id, fields, parameters }) {
  const method = parameters?.partial ? 'PATCH' : 'PUT'

  const responseData = await externalApiClient.makeApiRequest({
    method: method,
    path: `/contacts/${id}`,
    data: fields,
  })

  return {
    id: String(responseData.contact_id || id),
  }
}
```

## Input

| Property      | Type   | Description                                      |
| ------------- | ------ | ------------------------------------------------ |
| `id`          | string | The ID of the record to update                   |
| `fields`      | object | Updated fields in API format (after fieldsToApi) |
| `credentials` | object | Authentication credentials                       |
| `parameters`  | object | Method-specific parameters                       |

## Return Value

| Property | Type   | Description                  |
| -------- | ------ | ---------------------------- |
| `id`     | string | The ID of the updated record |
