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 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

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({ apiClient, id, fields, parameters }) {
  const method = parameters?.partial ? "PATCH" : "PUT"

  const response = await apiClient.request({
    method: method,
    url: `/contacts/${id}`,
    data: fields,
  })

  return {
    id: String(response.data.contact_id || id),
  }
}

Input

PropertyTypeDescription
idstringThe ID of the record to update
fieldsobjectUpdated fields in API format (after fieldsToApi)
credentialsobjectAuthentication credentials
parametersobjectMethod-specific parameters

Return Value

PropertyTypeDescription
idstringThe ID of the updated record