Skip to main content
Use a write action to create, update, or delete records in your customer’s system, whenever your app calls Ampersand’s Write API. This page focuses on writing data to existing fields. If you are looking to create new custom fields prior to writing data, please see Create or update custom fields.

Defining writes

To define a write action, add write as a key in your integration defined in amp.yaml, and add a list of standard and custom objects you want to write to.

Share mappings with read actions

If your read actions use field mappings, add inheritMapping: true to a write object to use the same mappings when writing. You then send the mapped field names in the write request, and Ampersand writes each one to the field that customer mapped it to.
  • The object needs a matching read object. Mappings are defined on read objects, so inheritMapping uses the read object with the same objectName.

Writing records

Once your users install an integration with a write action, your app can write data to their SaaS by making a POST call to Ampersand. The URL is in the format of: https://write.ampersand.ai/v1/projects/:projectIdOrName/integrations/:integrationId/objects/:objectName You can find your project ID and integration ID in the Ampersand Dashboard (look in the address bar) or you can run the following in the terminal to get projectId & integrationId:
objectName refers to the objectName key within the amp.yaml file that defines your integration. This must match the name of an object that exists within the SaaS instance.
Call the Write API from your backend with a server API key. API keys created for the UI Library currently can’t make write calls.
The record you send is passed to the provider in the provider’s own format, so use the provider’s field names and structure. The exception is mapped fields when you use inheritMapping.

Create, update, or delete a record

To create a new record, make a request to the Write endpoint with type being create. For example:
If you’d like to create records that are associated with other records, you can make a similar request with the associations parameter.
A synchronous write returns the result, including the provider’s recordId for the record:
An asynchronous write returns only an operationId.
If you need to pass additional headers when creating, updating, or deleting records for a provider, you can include those headers directly in the request body when calling the write endpoint. Ampersand will forward those headers as part of the outbound request to the provider.

Batch write

Batch write allows you to create or update multiple records in a single API call. This is useful when you need to write large amounts of data efficiently. You can include 1-100 records per batch.
Batch write is currently only supported for HubSpot and Salesforce.
To perform a batch write, use the same write endpoint but provide a batch array instead of a single record: https://write.ampersand.ai/v1/projects/:projectIdOrName/integrations/:integrationId/objects/:objectName Batch writes support both synchronous and asynchronous modes. By default, batch writes use partial success, i.e., successful records will be committed even if some records in the batch fail. To fail the entire batch when any record fails, set batchPolicy.allOrNone to true in your request.
HubSpot batch updates always result in partial success due to a provider limitation, regardless of the allOrNone setting.
To create multiple records in a batch, set type to create:
A batch write returns a result for each record, plus successCount and failureCount.

Auto batching

Ampersand can automatically group multiple single-record write requests together and execute them as a batch operation. This is useful when you want to reduce the amount of API quota that you are consuming in your customer’s SaaS instance.
Auto batching is currently only available for asynchronous mode and single-record writes (not batch writes).
When you enable auto batching, Ampersand will:
  1. Accumulate records: Multiple single-record write requests for the same installation, object, and write type (create or update) are automatically grouped together.
  2. Execute when ready: The batch executes when either:
    • 100 records have been accumulated, or
    • Maximum delay time has been reached (executes even if current batch has fewer than 100 records)
Each batch uses the max delay deadline set by the first record in that batch. This ensures records don’t wait indefinitely.

Configuration

The auto batch policy has two configuration options:
  • maxDelayMinutes (required): The maximum time to wait before executing the batch, even if it hasn’t reached 100 records. Minimum: 1, Maximum: 1440 (24 hours).
  • retryDeadlineHours (optional): The maximum time to keep retrying the batch write operation if it fails due to a retryable error. If not specified, defaults to 1 hour. Maximum allowed is 48 hours.
To enable auto batching, include autoBatchPolicy in the write API request, here’s an example:
In this example:
  • Ampersand waits for up to 5 minutes for additional records to come in before sending the current batch.
  • If 100 records accumulate before 5 minutes, the batch executes immediately.
  • If the batch write fails due to a retryable error, Ampersand will retry for up to 2 hours.

Monitor auto batch operations

You can monitor auto batch operations using the operation ID returned in the response. The operation ID represents the master operation for the batch. Use the Get Operation endpoint to check the status:
The operation status will show:
  • in_progress: The batch is accumulating records or executing.
  • success: The batch write completed successfully (may include partial success with some failed records).
  • failure: The batch write failed.

Write modes

Write actions support two modes: synchronous and asynchronous. The mode determines how the API handles your write request and when you receive a response. These modes apply to both single record writes and batch writes. Delete operations are always synchronous and do not use the mode field.
In synchronous mode, the write operation is processed immediately and the API waits for the operation to complete before returning a response.For single record writes, the response includes the created/updated record immediately. If the write operation fails, the API will return the error response.

Retry policy for async writes

Ampersand will automatically retry failed operations with exponential backoff until the default deadline of 1 hour. If this is not enough, you can specify a longer deadline of up to 48 hours.
Retry policies only apply to asynchronous mode.

Advanced use cases

These advanced use cases are currently only supported when creating or updating installations via the API or Headless UI.

Enabling deletion for an object

By default, delete operations are disabled. To enable deletion, set deletionSettings.enabled to true for the object when creating or updating an installation.
You can enable or disable deletion on a customer-by-customer basis using setEnableDeletion and setDisableDeletion from config.writeObject(). Learn more about pre-requisites for headless UI here.

Prevent overwriting of customer data

You can control whether a field is included in write requests. For example, you can avoid overwriting data the customer has changed, or leave a field blank on create and write to it only on update. writeOnCreate — whether to write the field when creating a record:
  • always (default): Always include the field on create
  • never: Never include the field on create
writeOnUpdate — whether to write the field when updating a record:
  • always (default): Always include the field on update
  • never: Never include the field on update (avoids overwriting customer changes)
  • ifEmpty: Only include the field if it’s currently empty. Supported for Salesforce and HubSpot only.
Example configurations:
  • Only set a field on create, never overwrite on update → writeOnCreate: "always", writeOnUpdate: "never"
  • Leave field blank on create, only fill on update → writeOnCreate: "never", writeOnUpdate: "always"
  • Fill on update only when the field is empty → writeOnUpdate: "ifEmpty"
  • Never write to the field for this customer → writeOnCreate: "never", writeOnUpdate: "never"
You can set overwrite behavior on a customer-by-customer basis using the function setFieldSettings. Learn more about pre-requisites for headless UI here.

Default values

Default values are applied to a field whenever that value is missing from the write request. We currently support string, boolean and number values.
You can set default values on a customer-by-customer basis using the setFieldSettings function. Learn more about pre-requisites for headless UI here.

Remove unmapped fields

If your write action is sharing mapping with read actions, we can drop unmapped fields from the write request before sending the request to the provider API. Please contact support@withampersand.com if you want to use this preview feature.

Combine use cases

Here is a full example for a request body to the Create Installation API that combines multiple use cases:
  • sharing mapping with read actions
  • applying default values
  • configuring when the field should be written to
For the headless UI version, see Configure features together.
For this installation, customSource has been mapped to the myCustomSource field in this customer’s HubSpot instance, the default value for this field is “myApp” and the field will only be written to when it is a create record request, and not an update request.