# Create or Update

The Create or Update Person operation is a powerful feature to manage contacts intelligently, preventing the creation of duplicates.

The system uses unique identification fields (such as email or phone) to check if the person already exists in the database.

* If the person is found, their data will be updated with the provided information.
* If the person is not found, a new record will be created.

This action is ideal for integrations with other platforms, where contact data is sent repeatedly and you need to ensure the consistency of your database.

#### How to Configure

1. In Hablla Studio, add the "People" block to your automation flow.
2. In the "Operation" field, select the "Create or Update" option.
3. Fill in the fields with the person's data. It is crucial to provide at least one unique identifier (Email or Phone) so that the search works.
4. Set the "Rule" field (`rule`) to determine how the system should behave if it finds multiple records with the same data.

***

### Parameters (Using Fields)

| Field               | Type              | Required? | Description                                                                                                                                                    |
| ------------------- | ----------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Rule (`rule`)       | Options List      | ✅ Yes     | Defines which record to update if more than one is found. Options: `older` (updates the oldest) or `newest` (updates the most recent). The default is `older`. |
| Full name           | Text              | ✅ Yes     | The person's full name.                                                                                                                                        |
| Privacy             | Options List      | ✅ Yes     | Defines the contact's legal basis. Options: `granted`, `interest`, etc.                                                                                        |
| Customer Status     | Options List      | ✅ Yes     | Classifies the person in the sales funnel. Options: `visitor`, `lead`, `customer`, etc.                                                                        |
| Emails              | Fields Collection | ✅ Yes     | Provide at least one email. This field is used to find the existing person.                                                                                    |
| Phones              | Fields Collection | ❌ No      | Provide one or more phones. This field is also used to find the existing person.                                                                               |
| About               | Long Text         | ❌ No      | An open field for notes or a biography about the person.                                                                                                       |
| Profile Photo URL   | Text              | ❌ No      | The link to the person's profile image.                                                                                                                        |
| Responsible (Owner) | User List         | ❌ No      | Associates or changes the users responsible for this person.                                                                                                   |
| Addresses           | Fields Collection | ❌ No      | Adds or updates the person's addresses.                                                                                                                        |
| Custom Fields       | Key-Value         | ❌ No      | Fills or changes values in custom fields.                                                                                                                      |

Export to Spreadsheets

> ⚠️ Important: For the "Update" functionality to work correctly, you must provide at least one of the identification fields: Emails or Phones.

***

### Structure (Using JSON)

The JSON body allows providing all data at once. The search logic and the update rule will be applied based on the submitted data.

JSON

```
{
  "rule": "newest",
  "name": "Maria Oliveira",
  "customer_status": "opportunity",
  "privacy": "granted",
  "emails": [
    {
      "email": "maria.oliveira@example.com"
    }
  ],
  "phones": [
    {
      "type": "personal",
      "phone": "+5521999991234",
      "is_whatsapp": true
    }
  ],
  "custom_fields": {
    "produto_interesse": "Premium Plan",
    "score": 85
  }
}
```

***

### 🚀 Example Use Case

Goal: Synchronize a list of contacts from a marketing automation platform (e.g., RD Station, Mailchimp) with Hablla, without creating duplicate contacts.

1. Create a flow that runs periodically (e.g., every 24 hours).
2. In that flow, add a step that fetches contacts recently updated on the marketing platform.
3. Use a loop (`loop`) to process each contact returned by the platform.
4. Inside the loop, add the "People" block with the "Create or Update" operation.
5. Map the fields from the contact coming from the external platform (name, email, phone, etc.) to the action parameters in Hablla.
6. Set the Rule as `newest` to ensure that, if there are duplicates in your database, the most recent one is always the one updated.

When running this flow, your Hablla database will be enriched with new contacts and updated with the latest information, keeping it clean and duplicate-free.
