# Contact Delete

> Remove the contact that triggered the automation from its audience.

The **contact delete** step removes the contact that triggered the automation from its [audience](https://www.mailblastr.com/docs/audiences/overview). Once deleted, the contact no longer receives emails from that audience and any remaining steps in the run are skipped. See [Using automations](https://www.mailblastr.com/docs/automations/overview) for the surrounding workflow.

Common use cases:

- **Compliance** — delete contacts as part of a data-removal workflow.
- **Churn** — remove a contact when a user stops using your service.
- **Unsubscribe flows** — automatically remove contacts who opt out.

## How it works

In the dashboard, add the **Delete contact** step — no configuration is required; it is ready as soon as you add it. Over the API, add a `contact_delete` step with an empty `config` object.

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.deleted" }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    { "from": "start", "to": "remove", "type": "default" }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.create({
  "name": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.deleted"
      }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "remove",
      "type": "default"
    }
  ]
})
```

**PHP**

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

$mailblastr->automations->create([
  'name' => "Remove churned users",
  'domain' => "yourdomain.com",
  'steps' => [
    [
      'key' => "start",
      'type' => "trigger",
      'config' => [
        'event_name' => "user.deleted"
      ]
    ],
    [
      'key' => "remove",
      'type' => "contact_delete",
      'config' => []
    ]
  ],
  'connections' => [
    [
      'from' => "start",
      'to' => "remove",
      'type' => "default"
    ]
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.create({
  "name": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": {
        "event_name": "user.deleted"
      }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    {
      "from": "start",
      "to": "remove",
      "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": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.deleted" }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    { "from": "start", "to": "remove", "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": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.deleted" }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    { "from": "start", "to": "remove", "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": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.deleted" }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    { "from": "start", "to": "remove", "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"": ""Remove churned users"",
  ""domain"": ""yourdomain.com"",
  ""steps"": [
    {
      ""key"": ""start"",
      ""type"": ""trigger"",
      ""config"": { ""event_name"": ""user.deleted"" }
    },
    {
      ""key"": ""remove"",
      ""type"": ""contact_delete"",
      ""config"": {}
    }
  ],
  ""connections"": [
    { ""from"": ""start"", ""to"": ""remove"", ""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": "Remove churned users",
  "domain": "yourdomain.com",
  "steps": [
    {
      "key": "start",
      "type": "trigger",
      "config": { "event_name": "user.deleted" }
    },
    {
      "key": "remove",
      "type": "contact_delete",
      "config": {}
    }
  ],
  "connections": [
    { "from": "start", "to": "remove", "type": "default" }
  ]
}'
```

> **Warning:** Deleting a contact is **permanent**. The contact and all of its properties are removed from the audience. If the contact needs to be re-added later, it must be created again.

## Configuration

The `config` object is empty — no additional fields are required.

```json
{
  "key": "remove_contact",
  "type": "contact_delete",
  "config": {}
}
```
