# 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.sendping.co/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 { SendPing } from 'sendping';

const mb = new SendPing('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 "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::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
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->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 sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.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
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

automation, err := client.Automations.Create(&sendping.CreateAutomationRequest{
    Name:   "Enrich contact on signup",
    Domain: "yourdomain.com",
    Steps: []sendping.AutomationStepInput{
        {
            Key:    "start",
            Type:   "trigger",
            Config: map[string]any{"event_name": "user.created"},
        },
        {
            Key:  "update",
            Type: "contact_update",
            Config: map[string]any{
                "first_name": map[string]any{"var": "event.firstName"},
                "last_name":  map[string]any{"var": "event.lastName"},
                "properties": map[string]any{
                    "company": map[string]any{"var": "event.company"},
                    "vip":     true,
                },
            },
        },
    },
    Connections: []sendping.AutomationConnectionInput{
        {From: "start", To: "update", Type: "default"},
    },
})
```

**Rust**

```rust
use sendping::{AutomationStepInput, ConnectionInput, CreateAutomationOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = CreateAutomationOptions::new("Enrich contact on signup", "yourdomain.com")
    .with_step(AutomationStepInput::new("trigger")
        .with_key("start")
        .with_config(serde_json::json!({"event_name":"user.created"})))
    .with_step(AutomationStepInput::new("contact_update")
        .with_key("update")
        .with_config(serde_json::json!({
            "first_name": {
                "var": "event.firstName"
            },
            "last_name": {
                "var": "event.lastName"
            },
            "properties": {
                "company": {
                    "var": "event.company"
                },
                "vip": true
            }
        })))
    .with_connection(ConnectionInput::new("start", "update").with_type("default"));
let _automation = mb.automations.create(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.AutomationConnection;
import co.sendping.requests.AutomationStep;
import co.sendping.requests.CreateAutomationRequest;
import java.util.Map;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

CreateAutomationRequest request = CreateAutomationRequest.builder()
        .name("Enrich contact on signup")
        .domain("yourdomain.com")
        .step(AutomationStep.builder()
                .key("start")
                .type("trigger")
                .config("event_name", "user.created")
                .build())
        .step(AutomationStep.builder()
                .key("update")
                .type("contact_update")
                .config("first_name", Map.of("var", "event.firstName"))
                .config("last_name", Map.of("var", "event.lastName"))
                .config("properties", Map.of(
                        "company", Map.of("var", "event.company"),
                        "vip", true))
                .build())
        .connection(AutomationConnection.of("start", "update", "default"))
        .build();

SendPingResponse response = sendping.automations().create(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.AutomationCreateAsync(new AutomationCreateOptions
{
    Name = "Enrich contact on signup",
    Domain = "yourdomain.com",
    Steps = new List<AutomationStepInput>
    {
        new()
        {
            Key = "start",
            Type = "trigger",
            Config = new Dictionary<string, object?>
            {
                ["event_name"] = "user.created",
            },
        },
        new()
        {
            Key = "update",
            Type = "contact_update",
            Config = new Dictionary<string, object?>
            {
                ["first_name"] = new Dictionary<string, object?>
                {
                    ["var"] = "event.firstName",
                },
                ["last_name"] = new Dictionary<string, object?>
                {
                    ["var"] = "event.lastName",
                },
                ["properties"] = new Dictionary<string, object?>
                {
                    ["company"] = new Dictionary<string, object?>
                    {
                        ["var"] = "event.company",
                    },
                    ["vip"] = true,
                },
            },
        },
    },
    Connections = new List<AutomationConnection>
    {
        new()
        {
            From = "start",
            To = "update",
            Type = "default",
        },
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/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.sendping.co/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.sendping.co/docs/audiences/properties). Each value is a hardcoded value or a variable reference. |
