# Contact Update

> Update a contact's name, subscription status, or custom properties during an automation.

The **contact update** step modifies the current contact's fields as the automation runs. You can update the contact's name, subscription status, or custom properties. See [Using automations](https://www.mailblastr.com/docs/automations/overview) for the surrounding workflow.

Common use cases:

- **Enrich profiles** — copy event data into the contact record.
- **Set flags** — mark contacts as VIP or churned based on their activity.
- **Sync properties** — keep custom properties up to date as events flow in.

## How it works

Add a `contact_update` step to the `steps` array and set the fields you want to change.

**Node.js**

```js
import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": { "var": "event.firstName" },
        "last_name": { "var": "event.lastName" },
        "properties": {
          "company": { "var": "event.company" },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "update", "type": "default" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.create({
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": {
          "var": "event.firstName"
        },
        "last_name": {
          "var": "event.lastName"
        },
        "properties": {
          "company": {
            "var": "event.company"
          },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "update",
      "type": "default"
    }
  ]
})
```

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

$mailblastr->automations->create([
  'name' => "Enrich contact on signup",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.created"
      ]
    ],
    [
      'key' => "update",
      'type' => "contact_update",
      'config' => [
        'first_name' => [
          'var' => "event.firstName"
        ],
        'last_name' => [
          'var' => "event.lastName"
        ],
        'properties' => [
          'company' => [
            'var' => "event.company"
          ],
          'vip' => true
        ]
      ]
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "update",
      'type' => "default"
    ]
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.create({
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.created"
      }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": {
          "var": "event.firstName"
        },
        "last_name": {
          "var": "event.lastName"
        },
        "properties": {
          "company": {
            "var": "event.company"
          },
          "vip": True
        }
      }
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "update",
      "type": "default"
    }
  ]
})
```

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, _ := http.NewRequest("POST", "https://api.mailblastr.com/automations", strings.NewReader(`{
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": { "var": "event.firstName" },
        "last_name": { "var": "event.lastName" },
        "properties": {
          "company": { "var": "event.company" },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "update", "type": "default" }
  ]
}`))
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    req.Header.Set("Content-Type", "application/json")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .post("https://api.mailblastr.com/automations")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": { "var": "event.firstName" },
        "last_name": { "var": "event.lastName" },
        "properties": {
          "company": { "var": "event.company" },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "update", "type": "default" }
  ]
}"#)
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/automations"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("""
{
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": { "var": "event.firstName" },
        "last_name": { "var": "event.lastName" },
        "properties": {
          "company": { "var": "event.company" },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "update", "type": "default" }
  ]
}
"""))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.mailblastr.com/automations");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{
  ""name"": ""Enrich contact on signup"",
  ""domain"": ""yourdomain.com"",
  ""steps"": [
    {
      ""key"": ""start"",
      ""type"": ""trigger"",
      ""config"": { ""event_name"": ""user.created"" }
    },
    {
      ""key"": ""update"",
      ""type"": ""contact_update"",
      ""config"": {
        ""first_name"": { ""var"": ""event.firstName"" },
        ""last_name"": { ""var"": ""event.lastName"" },
        ""properties"": {
          ""company"": { ""var"": ""event.company"" },
          ""vip"": true
        }
      }
    }
  ],
  ""connections"": [
    { ""from"": ""start"", ""to"": ""update"", ""type"": ""default"" }
  ]
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X POST 'https://api.mailblastr.com/automations' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Enrich contact on signup",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.created" }
    },
    {
      "key": "update",
      "type": "contact_update",
      "config": {
        "first_name": { "var": "event.firstName" },
        "last_name": { "var": "event.lastName" },
        "properties": {
          "company": { "var": "event.company" },
          "vip": true
        }
      }
    }
  ],
  "connections": [
    { "from": "start", "to": "update", "type": "default" }
  ]
}'
```

## Dynamic variables

Each field value can be a hardcoded value (string, number, boolean) or a dynamic variable reference using the `{ "var": "..." }` syntax. Variable references use dot-notation with one of these scopes:

- `event.*` — references a field from the triggering event payload (e.g. `event.firstName`).
- `contact.*` — references a field from the current contact (e.g. `contact.last_name`, `contact.properties.company`).

For more on variables, see the [Send Email](https://www.mailblastr.com/docs/automations/send-email) step documentation.

```json
{
  "key": "update",
  "type": "contact_update",
  "config": {
    "first_name": { "var": "event.firstName" },
    "last_name": { "var": "event.lastName" },
    "properties": {
      "company": { "var": "event.company" },
      "vip": true
    }
  }
}
```

## Configuration

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `config.first_name` | string | object | No | The contact's first name. Accepts a hardcoded string or a variable reference. |
| `config.last_name` | string | object | No | The contact's last name. Accepts a hardcoded string or a variable reference. |
| `config.unsubscribed` | boolean | object | No | The contact's unsubscribed status. Accepts a boolean or a variable reference. |
| `config.properties` | object | No | A map of custom contact properties to update. Keys correspond to your [contact properties](https://www.mailblastr.com/docs/audiences/properties). Each value is a hardcoded value or a variable reference. |
