# Mautic api for campaign events

**URL:** <https://forum.mautic.org/t/mautic-api-for-campaign-events/24098>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [May 14, 2022, 11:26pm UTC](https://forum.mautic.org/t/mautic-api-for-campaign-events/24098 "2022-05-14T23:26:18Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![patryk.gruszka](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/patryk.gruszka/32/9813_2.png) [@patryk.gruszka](https://forum.mautic.org/u/patryk.gruszka)\
**Post date:** [April 9, 2024, 9:43am UTC](https://forum.mautic.org/t/mautic-api-for-campaign-events/24098/6 "2024-04-09T09:43:36Z")

</div>

You can use the create campaign API endpoint to create the events.

The payload should contain:

- The starting segment or form definition (`lists` or `forms` in the JSON)
- Events temporary IDs starting with the keyword ‘new’, they will be replaced with real IDs when the campaign is created
- Correct references to parent events
- Nodes and connections settings in `canvasSettings`

Here is an example payload `POST /api/campaigns/new`:

```auto
{
    "isPublished": true,
    "name": "API Campaign",
    "description": null,
    "allowRestart": 0,
    "events": [
        {
            "id": "new1",
            "name": "Contact field value",
            "type": "lead.field_value",
            "eventType": "condition",
            "order": 1,
            "properties": {
                "canvasSettings": {
                    "droppedX": "520",
                    "droppedY": "155"
                },
                "name": "",
                "triggerMode": "immediate",
                "triggerDate": null,
                "triggerInterval": "1",
                "triggerIntervalUnit": "d",
                "triggerHour": "",
                "triggerRestrictedStartHour": "",
                "triggerRestrictedStopHour": "",
                "anchor": "leadsource",
                "properties": {
                    "field": "email",
                    "operator": "endsWith",
                    "value": "example.com"
                },
                "type": "lead.field_value",
                "eventType": "condition",
                "anchorEventType": "source",
                "buttons": {
                    "save": ""
                },
                "field": "email",
                "operator": "endsWith",
                "value": "example.com"
            },
            "triggerDate": null,
            "triggerInterval": 1,
            "triggerIntervalUnit": "d",
            "triggerHour": null,
            "triggerRestrictedStartHour": null,
            "triggerRestrictedStopHour": null,
            "triggerRestrictedDaysOfWeek": [],
            "triggerMode": "immediate",
            "decisionPath": null,
            "parent": null
        },
        {
            "id": "new2",
            "name": "Modify contact's tags",
            "type": "lead.changetags",
            "eventType": "action",
            "order": 2,
            "properties": {
                "canvasSettings": {
                    "droppedX": "710",
                    "droppedY": "291"
                },
                "name": "",
                "triggerMode": "immediate",
                "triggerDate": null,
                "triggerInterval": "1",
                "triggerIntervalUnit": "d",
                "triggerHour": "",
                "triggerRestrictedStartHour": "",
                "triggerRestrictedStopHour": "",
                "anchor": "yes",
                "properties": {
                    "add_tags": [
                        "2"
                    ]
                },
                "type": "lead.changetags",
                "eventType": "action",
                "anchorEventType": "condition",
                "buttons": {
                    "save": ""
                },
                "triggerRestrictedDaysOfWeek": [],
                "add_tags": [
                    "example"
                ],
                "remove_tags": []
            },
            "triggerDate": null,
            "triggerInterval": 1,
            "triggerIntervalUnit": "d",
            "triggerHour": null,
            "triggerRestrictedStartHour": null,
            "triggerRestrictedStopHour": null,
            "triggerRestrictedDaysOfWeek": [],
            "triggerMode": "immediate",
            "decisionPath": "yes",
            "parent": {"id": "new1"}
        }
    ],
    "forms": [],
    "lists": [
        {
            "createdByUser": "Admin User",
            "modifiedByUser": null,
            "id": 9,
            "name": "Segment Test 1",
            "publicName": "Segment Test 1",
            "alias": "segment-test-1",
            "description": null,
            "category": null
        }
    ],
    "canvasSettings": {
        "nodes": [
            {
                "id": "new1",
                "positionX": "810",
                "positionY": "186"
            },
            {
                "id": "new2",
                "positionX": "710",
                "positionY": "291"
            },
            {
                "id": "lists",
                "positionX": "833",
                "positionY": "50"
            }
        ],
        "connections": [
            {
                "sourceId": "lists",
                "targetId": "new1",
                "anchors": {
                    "source": "leadsource",
                    "target": "top"
                }
            },
            {
                "sourceId": "new1",
                "targetId": "new2",
                "anchors": {
                    "source": "yes",
                    "target": "top"
                }
            }
        ]
    }
}

```

---

_[View the full topic](https://forum.mautic.org/t/mautic-api-for-campaign-events/24098)._
