Upsert Member Action
The Upsert Member action creates or updates a member when triggered by an incoming webhook or integration event. It is the primary action for integration-based onboarding flows — for example, automatically enrolling a patient when eClinicalWorks or Salesforce sends a webhook with their contact information.
How it fits together: "Upsert Member" is an Action type in Gravity Rail. It is triggered by events that carry an incoming member record (such as a webhook payload), and it writes that record to the workspace as a new or updated member.
When to Use
- Integration onboarding — Automatically enroll members when an external system (EHR, CRM, scheduling system) sends a webhook.
- Record sync — Keep member data in sync by re-running the upsert whenever an external system updates a record.
- Selective creation — Create members only if they don't yet exist (
create_onlywithskipIfExists). - Selective updates — Update only members who are already enrolled (
update_only).
Prerequisites
- An Event Rule configured to fire on an incoming webhook event
- The webhook payload must include at least one identity field:
external_id,email, orphone - The workspace must have the MEMBER_UPSERT_REQUEST capability enabled (included by default on webhook-triggered rules)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
behavior | enum | upsert | Controls create/update logic. See values below. |
skipIfExists | boolean | false | When behavior is create_only: silently skip instead of failing when the member already exists. |
skipIfNotFound | boolean | false | When behavior is update_only: silently skip instead of failing when the member is not found. |
behavior Values
| Value | What It Does |
|---|---|
upsert | Create the member if they don't exist; update them if they do. (Default) |
create_only | Only create new members. If the member already exists, the action fails unless skipIfExists is true. |
update_only | Only update existing members. If the member is not found, the action fails unless skipIfNotFound is true. |
Identity Lookup Order
The action looks up existing members in this order:
external_id— the identifier from your external systememailphone
At least one of these must be present in the webhook payload for the action to run.
Setting Up the Action
1. Create an Event Rule
Go to Actions in your workspace and click New Action.
2. Set the Trigger
Choose a trigger that carries incoming member data, such as Webhook Received on your configured webhook endpoint.
3. Select "Upsert Member" as the action type
In the action type dropdown, select Upsert Member.
4. Configure behavior
Choose the behavior that matches your use case:
upsert— Safe default. Works for both new members and updates.create_only— Use when you only want to enroll new members and never overwrite existing records.update_only— Use when members must already exist (e.g., syncing data after an initial enrollment step).
5. Configure skip flags (optional)
- Enable Skip if exists (
skipIfExists) when usingcreate_onlyto silently ignore duplicate webhooks instead of logging an error. - Enable Skip if not found (
skipIfNotFound) when usingupdate_onlyto silently ignore webhooks for members who haven't enrolled yet.
6. Save the action
Click Save. The action will run whenever the trigger fires.
Worked Example: Automatic Patient Enrollment from a Webhook
Goal: Automatically create a member when a scheduling system sends a new patient webhook. If the patient already exists, update their record.
Event Rule setup:
- Trigger: Webhook Received (your scheduling system endpoint)
- Action: Upsert Member
behavior:upsertskipIfExists:false(not needed forupsertmode)
Webhook payload (sent by the scheduling system):
{
"external_id": "PT-10042",
"email": "placeholder@example.com",
"first_name": "Alex",
"last_name": "Sample",
"phone": "+15550001234",
"labels": ["new-patient"],
"data": {
"intake_form": {
"preferred_language": "en",
"appointment_type": "initial"
}
}
}
Replace placeholder values with your actual field names. Do not include real patient data in action configurations or test setups.
What happens:
- The scheduling system sends a webhook when the patient is scheduled.
- Gravity Rail fires the event rule.
- The Upsert Member action looks up
PT-10042in the workspace. - If not found: creates a new member with the provided name, email, phone, label
new-patient, and intake form data. - If found: updates the existing member's fields with the incoming data.
Error Outcomes
| Situation | behavior | Skip flag | Result |
|---|---|---|---|
| Member not found | update_only | skipIfNotFound: false | Action fails, error logged |
| Member not found | update_only | skipIfNotFound: true | Action skipped silently |
| Member already exists | create_only | skipIfExists: false | Action fails, error logged |
| Member already exists | create_only | skipIfExists: true | Action skipped silently |
| No identity field in payload | any | any | Action fails — webhook payload must include external_id, email, or phone |
Tips
- Use
upsertfor most cases — It handles both creation and updates safely and is idempotent. - Prefer
skipIfExistsovercreate_onlyalone — Duplicate webhooks are common;skipIfExists: trueprevents noisy errors in your action logs. - Check action logs — Failed actions show the error reason (e.g.,
member not found,missing identity fields) in the Actions log view. - Combine with CEL conditions — Use CEL conditions to filter which webhooks trigger the upsert (e.g., only process records of a specific type).
Related
- Actions Overview — How event rules and action types work
- CEL Expressions — Filter when actions fire
- Webhooks — Configure incoming webhooks for your workspace