# Update Automation Step

> PATCH /automations/:id/steps/:stepId — edit a step in place (type/config) on a disabled automation.

`PATCH /automations/:id/steps/:stepId`

Updates a step's `type` and/or `config` in place. The step's **graph key stays stable**, so any [connections](https://www.mailblastr.com/docs/automations/connections) pointing at it keep working — unlike delete-and-re-add, which drops the key and its edges. The automation must be **disabled** ([stop](https://www.mailblastr.com/docs/api/automations-stop) or disable it first). Returns the updated step.

The body is the same shape as [Add Step](https://www.mailblastr.com/docs/api/automations-add-step): `type` (required) plus the type-specific `config`. See the [Steps](https://www.mailblastr.com/docs/automations/steps) page for each type's config shape.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The automation id. |
| `stepId` | string | Yes | The id of the step to update. |

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | string | Yes | The step type (e.g. `send_email`, `delay`, `condition`). |
| `config` | object | No | The type-specific configuration that replaces the step's current config. |

**Node.js**

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

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.updateStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', '9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d', {
  "type": "delay",
  "config": { "duration": "2 days" }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Automations.update_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d", {
  "type": "delay",
  "config": {
    "duration": "2 days"
  }
})
```

**PHP**

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

$mailblastr->automations->updateStep('c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd', '9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d', [
  'type' => "delay",
  'config' => [
    'duration' => "2 days"
  ]
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Automations.update_step("c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd", "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d", {
  "type": "delay",
  "config": {
    "duration": "2 days"
  }
})
```

**Go**

```go
package main

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

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps/9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d", strings.NewReader(`{
  "type": "delay",
  "config": { "duration": "2 days" }
}`))
    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()
        .patch("https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps/9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{
  "type": "delay",
  "config": { "duration": "2 days" }
}"#)
        .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/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps/9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{
  "type": "delay",
  "config": { "duration": "2 days" }
}
"""))
    .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.Patch, "https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps/9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{
  ""type"": ""delay"",
  ""config"": { ""duration"": ""2 days"" }
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X PATCH 'https://api.mailblastr.com/automations/c9b16d4f-ba6c-4e2e-b044-6bf4404e57fd/steps/9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "type": "delay",
  "config": { "duration": "2 days" }
}'
```

### Response

```json
{
  "id": "9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d",
  "key": "welcome",
  "type": "delay",
  "position": 0,
  "config": { "duration": "2 days" }
}
```

Returns `not_found` (404) if the automation or step does not exist, and `validation_error` (422) if the automation is enabled (disable it first) or the step body is invalid. See [Errors](https://www.mailblastr.com/docs/api/errors).
