Historical Sync Inbound Example

This config showcases how to define a one-time historical sync in an app config. In this example, you will find two data_intake objects, one for webhook and one for polling. The polling is used to perform a one-time sync of all historical data, and the webhook is used for the remainder of the application lifecycle to keep data in sync.

To learn more about historical sync, please refer to our Configuration Walkthrough.

{
  "$version": "2",
  "api": {
    "base_url": "https://api.your-company.com"
  },
  "auth": {
    "my-basic": {
      "type": "basic",
      "verify_url": "https://api.your-company.com/auth",
      "defined_fields": {
        "username": {
          "label": "Username",
          "placeholder": "Enter username for your account",
          "help_text": "Enter anything"
        },
        "password": {
          "label": "Password",
          "placeholder": "Enter the account password",
          "help_text": "Enter anything"
        }
      }
    }
  },
  "data_intake": [
    {
      "name": "webhook",
      "type": "webhook",
      "scope": "workflow",
      "create": {
        "!http": {
          "body": {
            "url": "${webhook.url}"
          },
          "headers": {
            "content-type": "application/json"
          },
          "method": "POST",
          "url": "https://api.your-company.com/hooks"
        }
      }
    },
    {
      "name": "historical-sync",
      "type": "polling",
      "initial_setup": {
        "!jq": "{ polling_state: {iterations: 1 }}"
      },
      "request": {
        "!jq": "{ polling_state: {iterations: (${polling_state.iterations} + 1)}, results: [{ email: \"historical_record${polling_state.iterations}@mailserver.testing\", first_name: \"Record${polling_state.iterations}\", last_name: \"Historical\" }], iterate: (if ${polling_state.iterations} > 13 then false else true end) }"
      }
    }
  ],
  "workflows": [
    {
      "label": "Webhook with Historical Polling",
      "description": "Webhook with Historical Polling",
      "name": "historical-sync",
      "type": "generic",
      "data_intake": "webhook",
      "auth": "my-basic",
      "resource_labels": {
        "webhook_events": ["Event A", "Event B"],
        "webhook_objects_updated": ["Object A"],
        "historical_sync_events": ["Sync Event A"],
        "historical_sync_objects_updated": ["Sync A", "Sync B"]
      },
      "historical_data_intake": "historical-sync",
      "setup": {
        "connect": {
          "label": "Connect",
          "describe_connection": {
            "!pipe": [
              {
                "!http": {
                  "method": "GET",
                  "url": "https://api.your-company.com/auth"
                }
              },
              {
                "!jq": ".body | {account_id: \"accountuuid\", description: \"Name - Email\" }"
              }
            ]
          }
        },
        "select": {
          "label": "Info pane",
          "description": "Without form fields, this is plain text info",
          "form_fields": [],
          "describe_selection": {
            "resource_id": {
              "!jq": "\"Historical\" + (now|tostring)"
            },
            "display": {
              "!jq": "\"Event Subscription\""
            }
          }
        },
        "map": {
          "label": "Mapping",
          "describe_source": {
            "label": "Contact Data",
            "options": {
              "!jq": "[ {id: \"email\", title: \"Email\"}, {id: \"first_name\", title: \"First Name\"}, {id: \"last_name\", title: \"Last Name\"} ]"
            }
          },
          "describe_target": {
            "label": "ActiveCampaign",
            "options": {
              "!resource": "ActiveCampaignContact.fields"
            }
          }
        }
      },
      "data_pipeline": {
        "source": {
          "!jq": "."
        },
        "target": {
          "!resource": "ActiveCampaignContact"
        }
      }
    }
  ]
}