Update
The update method modifies an existing record in the collection.
Configuration Example
# 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 updatesConfiguration Options
fields(array): Whitelist of fields that can be updatedexcludedFields(array): Fields that cannot be updated
Implementation Examples
REST API Mapping Implementation (Recommended)
File: update.rest.yml
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
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
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 | 
Updated 10 days ago
