Automations
Invoke an ad hoc Automation
Runs a series of automation steps supplied inline, without a saved template, and returns a runId.
POST
/
automations
/
invoke
JavaScript
import Courier from '@trycourier/courier';
const client = new Courier({
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
});
const automationInvokeResponse = await client.automations.invoke.invokeAdHoc({
automation: {
cancelation_token: 'delay-send--user-yes--abc-123',
steps: [
{ action: 'delay', until: '20240408T080910.123' },
{ action: 'send', template: '64TP5HKPFTM8VTK1Y75SJDQX9JK0' },
],
},
data: { name: 'Foo' },
profile: { tenant_id: 'abc-123' },
recipient: 'user-yes',
});
console.log(automationInvokeResponse.runId);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
automation_invoke_response = client.automations.invoke.invoke_ad_hoc(
automation={
"cancelation_token": "delay-send--user-yes--abc-123",
"steps": [{
"action": "delay",
"until": "20240408T080910.123",
}, {
"action": "send",
"template": "64TP5HKPFTM8VTK1Y75SJDQX9JK0",
}],
},
data={
"name": "Foo"
},
profile={
"tenant_id": "abc-123"
},
recipient="user-yes",
)
print(automation_invoke_response.run_id)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
automationInvokeResponse, err := client.Automations.Invoke.InvokeAdHoc(context.TODO(), courier.AutomationInvokeInvokeAdHocParams{
Automation: courier.AutomationInvokeInvokeAdHocParamsAutomation{
CancelationToken: courier.String("delay-send--user-yes--abc-123"),
Steps: []courier.AutomationInvokeInvokeAdHocParamsAutomationStepUnion{{
OfAutomationDelayStep: &courier.AutomationInvokeInvokeAdHocParamsAutomationStepAutomationDelayStep{
Action: "delay",
Until: courier.String("20240408T080910.123"),
},
}, {
OfAutomationSendStep: &courier.AutomationInvokeInvokeAdHocParamsAutomationStepAutomationSendStep{
Action: "send",
Template: courier.String("64TP5HKPFTM8VTK1Y75SJDQX9JK0"),
},
}},
},
Data: map[string]any{
"name": "Foo",
},
Profile: map[string]any{
"tenant_id": "abc-123",
},
Recipient: courier.String("user-yes"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", automationInvokeResponse.RunID)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.automations.AutomationInvokeResponse;
import com.courier.models.automations.invoke.InvokeInvokeAdHocParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
InvokeInvokeAdHocParams params = InvokeInvokeAdHocParams.builder()
.automation(InvokeInvokeAdHocParams.Automation.builder()
.addStep(InvokeInvokeAdHocParams.Automation.Step.AutomationDelayStep.builder()
.action(InvokeInvokeAdHocParams.Automation.Step.AutomationDelayStep.Action.DELAY)
.build())
.addStep(InvokeInvokeAdHocParams.Automation.Step.AutomationSendStep.builder()
.action(InvokeInvokeAdHocParams.Automation.Step.AutomationSendStep.Action.SEND)
.build())
.build())
.build();
AutomationInvokeResponse automationInvokeResponse = client.automations().invoke().invokeAdHoc(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
automation_invoke_response = courier.automations.invoke.invoke_ad_hoc(automation: {steps: [{action: :delay}, {action: :send}]})
puts(automation_invoke_response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$automationInvokeResponse = $client->automations->invoke->invokeAdHoc(
automation: [
'steps' => [
[
'action' => 'delay',
'duration' => 'duration',
'until' => '20240408T080910.123',
],
[
'action' => 'send',
'brand' => 'brand',
'data' => ['foo' => 'bar'],
'profile' => ['foo' => 'bar'],
'recipient' => 'recipient',
'template' => '64TP5HKPFTM8VTK1Y75SJDQX9JK0',
],
],
'cancelationToken' => 'delay-send--user-yes--abc-123',
],
brand: 'brand',
data: ['name' => 'bar'],
profile: ['tenant_id' => 'bar'],
recipient: 'user-yes',
template: 'template',
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($automationInvokeResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using Invoke = TryCourier.Models.Automations.Invoke;
CourierClient client = new();
Invoke::InvokeInvokeAdHocParams parameters = new()
{
Automation = new()
{
Steps =
[
new Invoke::AutomationDelayStep()
{
Action = Invoke::Action.Delay,
Duration = "duration",
Until = "20240408T080910.123",
},
new Invoke::AutomationSendStep()
{
Action = Invoke::AutomationSendStepAction.Send,
Brand = "brand",
Data = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Profile = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Recipient = "recipient",
Template = "64TP5HKPFTM8VTK1Y75SJDQX9JK0",
},
],
CancelationToken = "delay-send--user-yes--abc-123",
},
};
var automationInvokeResponse = await client.Automations.Invoke.InvokeAdHoc(parameters);
Console.WriteLine(automationInvokeResponse);courier automations:invoke invoke-ad-hoc \
--api-key 'My API Key' \
--automation '{steps: [{action: delay}, {action: send}]}'curl --request POST \
--url https://api.courier.com/automations/invoke \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"name": "Foo"
},
"profile": {
"tenant_id": "abc-123"
},
"recipient": "user-yes",
"automation": {
"cancelation_token": "delay-send--user-yes--abc-123",
"steps": [
{
"action": "delay",
"until": "20240408T080910.123"
},
{
"action": "send",
"template": "64TP5HKPFTM8VTK1Y75SJDQX9JK0"
}
]
}
}
'{
"runId": "1-65f240a0-47a6a120c8374de9bcf9f22c"
}Authorizations
Headers
A unique key that makes this request idempotent. If Courier receives another request with the same Idempotency-Key, it returns the stored response from the first request without performing the operation again (including the original status code and any error). Use it to safely retry POST requests after network failures without risking duplicate sends. The key is scoped to this endpoint.
Body
application/json
⌘I
JavaScript
import Courier from '@trycourier/courier';
const client = new Courier({
apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
});
const automationInvokeResponse = await client.automations.invoke.invokeAdHoc({
automation: {
cancelation_token: 'delay-send--user-yes--abc-123',
steps: [
{ action: 'delay', until: '20240408T080910.123' },
{ action: 'send', template: '64TP5HKPFTM8VTK1Y75SJDQX9JK0' },
],
},
data: { name: 'Foo' },
profile: { tenant_id: 'abc-123' },
recipient: 'user-yes',
});
console.log(automationInvokeResponse.runId);import os
from courier import Courier
client = Courier(
api_key=os.environ.get("COURIER_API_KEY"), # This is the default and can be omitted
)
automation_invoke_response = client.automations.invoke.invoke_ad_hoc(
automation={
"cancelation_token": "delay-send--user-yes--abc-123",
"steps": [{
"action": "delay",
"until": "20240408T080910.123",
}, {
"action": "send",
"template": "64TP5HKPFTM8VTK1Y75SJDQX9JK0",
}],
},
data={
"name": "Foo"
},
profile={
"tenant_id": "abc-123"
},
recipient="user-yes",
)
print(automation_invoke_response.run_id)package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
automationInvokeResponse, err := client.Automations.Invoke.InvokeAdHoc(context.TODO(), courier.AutomationInvokeInvokeAdHocParams{
Automation: courier.AutomationInvokeInvokeAdHocParamsAutomation{
CancelationToken: courier.String("delay-send--user-yes--abc-123"),
Steps: []courier.AutomationInvokeInvokeAdHocParamsAutomationStepUnion{{
OfAutomationDelayStep: &courier.AutomationInvokeInvokeAdHocParamsAutomationStepAutomationDelayStep{
Action: "delay",
Until: courier.String("20240408T080910.123"),
},
}, {
OfAutomationSendStep: &courier.AutomationInvokeInvokeAdHocParamsAutomationStepAutomationSendStep{
Action: "send",
Template: courier.String("64TP5HKPFTM8VTK1Y75SJDQX9JK0"),
},
}},
},
Data: map[string]any{
"name": "Foo",
},
Profile: map[string]any{
"tenant_id": "abc-123",
},
Recipient: courier.String("user-yes"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", automationInvokeResponse.RunID)
}
package com.courier.example;
import com.courier.client.CourierClient;
import com.courier.client.okhttp.CourierOkHttpClient;
import com.courier.models.automations.AutomationInvokeResponse;
import com.courier.models.automations.invoke.InvokeInvokeAdHocParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
CourierClient client = CourierOkHttpClient.fromEnv();
InvokeInvokeAdHocParams params = InvokeInvokeAdHocParams.builder()
.automation(InvokeInvokeAdHocParams.Automation.builder()
.addStep(InvokeInvokeAdHocParams.Automation.Step.AutomationDelayStep.builder()
.action(InvokeInvokeAdHocParams.Automation.Step.AutomationDelayStep.Action.DELAY)
.build())
.addStep(InvokeInvokeAdHocParams.Automation.Step.AutomationSendStep.builder()
.action(InvokeInvokeAdHocParams.Automation.Step.AutomationSendStep.Action.SEND)
.build())
.build())
.build();
AutomationInvokeResponse automationInvokeResponse = client.automations().invoke().invokeAdHoc(params);
}
}require "courier"
courier = Courier::Client.new(api_key: "My API Key")
automation_invoke_response = courier.automations.invoke.invoke_ad_hoc(automation: {steps: [{action: :delay}, {action: :send}]})
puts(automation_invoke_response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Courier\Client;
use Courier\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API Key');
try {
$automationInvokeResponse = $client->automations->invoke->invokeAdHoc(
automation: [
'steps' => [
[
'action' => 'delay',
'duration' => 'duration',
'until' => '20240408T080910.123',
],
[
'action' => 'send',
'brand' => 'brand',
'data' => ['foo' => 'bar'],
'profile' => ['foo' => 'bar'],
'recipient' => 'recipient',
'template' => '64TP5HKPFTM8VTK1Y75SJDQX9JK0',
],
],
'cancelationToken' => 'delay-send--user-yes--abc-123',
],
brand: 'brand',
data: ['name' => 'bar'],
profile: ['tenant_id' => 'bar'],
recipient: 'user-yes',
template: 'template',
idempotencyKey: 'order-ORD-456-user-123',
xIdempotencyExpiration: '1785312000',
);
var_dump($automationInvokeResponse);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using System.Collections.Generic;
using System.Text.Json;
using TryCourier;
using Invoke = TryCourier.Models.Automations.Invoke;
CourierClient client = new();
Invoke::InvokeInvokeAdHocParams parameters = new()
{
Automation = new()
{
Steps =
[
new Invoke::AutomationDelayStep()
{
Action = Invoke::Action.Delay,
Duration = "duration",
Until = "20240408T080910.123",
},
new Invoke::AutomationSendStep()
{
Action = Invoke::AutomationSendStepAction.Send,
Brand = "brand",
Data = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Profile = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
Recipient = "recipient",
Template = "64TP5HKPFTM8VTK1Y75SJDQX9JK0",
},
],
CancelationToken = "delay-send--user-yes--abc-123",
},
};
var automationInvokeResponse = await client.Automations.Invoke.InvokeAdHoc(parameters);
Console.WriteLine(automationInvokeResponse);courier automations:invoke invoke-ad-hoc \
--api-key 'My API Key' \
--automation '{steps: [{action: delay}, {action: send}]}'curl --request POST \
--url https://api.courier.com/automations/invoke \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"data": {
"name": "Foo"
},
"profile": {
"tenant_id": "abc-123"
},
"recipient": "user-yes",
"automation": {
"cancelation_token": "delay-send--user-yes--abc-123",
"steps": [
{
"action": "delay",
"until": "20240408T080910.123"
},
{
"action": "send",
"template": "64TP5HKPFTM8VTK1Y75SJDQX9JK0"
}
]
}
}
'{
"runId": "1-65f240a0-47a6a120c8374de9bcf9f22c"
}