Read Actions
A read action reads data from your customer’s SaaS and send them to Destinations that you define.
Defining reads
To read an object, you need to specify:
- objectName: to indicate which object you’d like to read. This should match the name of the object in the official documentation for the SaaS API.
- destination: the name of the destination that you’ve defined
- schedule: how frequently the read should happen. This value must be a schedule in cron syntax
- backfill (optional): whether Ampersand should read historical data when a customer installs an integration. If omitted, then Ampersand will only incrementally read data that has been created or updated after that point. See Backfill behavior for details.
...
objects:
- objectName: lineItem
destination: lineItemWebhook
schedule: "0 */12 * * *" # every 12 hours
backfill:
defaultPeriod:
days: 30
...
On the roadmap
The ability for your users to define their own sync schedules.
Required fields and optional fields
Fields can be either be required or optional. If a field is required, then all users who install this integration will need to give your app read access to that field. If a field is optional, then users can choose whether they’d like your app to read that field. For these fields, you will specify:
- fieldName: the name of the field from the official SaaS API documentation.
objects:
- objectName: contact
destination: contactWebhook
schedule: "0 */12 * * *" # every 12 hours
requiredFields:
- fieldName: firstname
- fieldName: lastname
- fieldName: email
optionalFields:
- fieldName: company
Embeddable UI produced by the above config
Allow users to pick from all fields
If you want to give your user the option to pick from any of the fields in their object, use optionalFieldsAuto: all
. The UI component will populate a list of all the fields pulled from that object (including custom fields) and allow them to pick which ones your app will be able to read.
objects:
- objectName: contact
destination: contactWebhook
schedule: "0 */12 * * *" # every 12 hours
requiredFields:
- fieldName: firstname
- fieldName: lastname
- fieldName: email
# All other fields are optional
optionalFieldsAuto: all
Field mappings
You might want to ask your users during the set up of the integration to map a field (standard or custom) to a concept in your product, because your various customers might be using different fields for the same purpose. Field mappings can either be inside requiredFields
or optionalFields
.
For these fields, you’ll specify:
- mapToName: when Ampersand delivers the data from this field to you, this is the name that will be used to identify the field.
- mapToDisplayName: the text to display to the user in the UI component when asking them to select a custom field (e.g. For the yaml example below, the text will say, “Which of your custom fields map to Contact Notes?“)
- default (optional): the default field, you should only use standard fields as defaults.
- prompt (optional): additional context that you want to show your user in the UI Component about this field. This should be a full sentence.
objects:
- objectName: contact
destination: contactWebhook
optionalFields:
# field that your app created
- fieldName: myAppPriorityScore
# field that your user created
- mapToName: notes
mapToDisplayName: Contact Notes
prompt: These are notes that you would like to surface in our app.
...
Embeddable UI produced by the above config
Backfill behavior
Backfill behavior describes whether Ampersand will do an initial read of your customer’s historic data when they connect their SaaS instance, and how far back data will be read. For example, if your integration reads a customer’s contacts stored in their CRM, you can configure whether you want to only read new and updated contacts going forward, or if you also want to do an initial backfill of the pre-existing contacts in their CRM.
No backfill
If you only want to read new and updated records moving forward and do not wish to read any pre-existing records, then you can simply omit the backfill
key in the integration definition, or you can write 0 days as the default period.
objects:
- objectName: contact
backfill:
defaultPeriod:
days: 0 # Omitting backfill object will also default to 0 days.
...
Full historical backfill
If you want to do a full backfill of all the existing records when a customer connects their SaaS instance, set fullHistory
to true. If you have customers that have large SaaS instances, please ensure that your webhook endpoint can handle a high number of messages in quick succession. You may find it helpful to use a webhook gateway solution like Hookdeck.
objects:
- objectName: contact
backfill:
defaultPeriod:
fullHistory: true
...
Limited time backfill
You can select a specific time frame for backfill, such as “the last 30 days” or “the last 90 days”. Here’s an example of how to do so:
objects:
- objectName: contact
backfill:
defaultPeriod:
days: 30 # Backfill the last 30 days of data
...
Full example
specVersion: 1.0.0
integrations:
- name: readSalesforce
provider: salesforce
read:
objects:
- objectName: account
destination: accountWebhook
schedule: "0 */12 * * *" # every 12 hours
requiredFields:
- fieldName: id
- fieldName: name
- fieldName: industry
optionalFields:
- fieldName: annualrevenue
- fieldName: website
- objectName: contact
destination: contactWebhook
schedule: "0 */12 * * *" # every 12 hours
requiredFields:
- fieldName: id
- fieldName: firstname
- fieldName: lastname
- fieldName: email
- mapToName: pronoun
mapToDisplayName: Pronoun
prompt: We will use this word when addressing this person in emails we send out.
optionalFieldsAuto: all
Example webhook message
Ampersand will do reads at the schedule you specify in amp.yaml
. If there are any new or updated records since our last read, Ampersand will send you webhook messages. For the sample integration above, here’s what a sample webhook message might look like for the Contact object:
{
"projectId": "ampersand-project-id",
"provider": "salesforce",
"workspace": "salesforce-subdomain",
"groupRef": "xyz-company",
"groupName": "XYZ Company",
"installationId": "installation-id",
"objectName": "Contact",
"result": [
{
"fields": {
"id": "001Dp00000P8QurIAF",
"firstname": "Sally",
"lastname": "Jones",
"email": "[[email protected]](/cdn-cgi/l/email-protection)"
},
"mappedFields": {
"pronoun": "she",
},
"raw": {
"id": "001Dp00000P8QurIAF",
"firstname": "Sally",
"lastname": "Jones",
"email": "[[email protected]](/cdn-cgi/l/email-protection)",
"pronoun_custom_field": "she",
// ... other fields for the record
}
},
{
"fields": {
"id": "001Dp00000P9BusEIS",
"firstname": "Taylor",
"lastname": "Lao",
"email": "[[email protected]](/cdn-cgi/l/email-protection)"
},
"mappedFields": {
"pronoun": "they",
},
"raw": {
"id": "001Dp00000P9BusEIS",
"firstname": "Taylor",
"lastname": "Lao",
"email": "[[email protected]](/cdn-cgi/l/email-protection)"
"pronoun_custom_field": "they",
// ... other fields for the record
}
}
]}
Was this page helpful?