> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> Learn how to setup an Event in Refold

Events are the trigger entities that are used to define a start point of a workflow and can be triggered using the [REST APIs](https://docs.gocobalt.io/api-reference/event/trigger-an-event-from-your-application) or the Event URL assigned for the Organization.
Think of these custom events as signals sent from your app using the Refold SDK or Event API to kick off different processes.

Refold events are `common models`. This means once you set it up, one event can make several workflows get executed. This is handy when you want the same event to do similar things in different apps.

#### Creating an event

An event model contains name of the event and the trigger payload. The trigger payload contains sample data schema that can be used as data variables and are used
inside a workflow as placeholders while defining the workflow. The actual data passed while triggering the event takes place of those variables inside the workflows.

To create an event, go to Settings > Developer > Events,

Click on `New Event` and select a model.

<img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Developer/create-event.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=bcdb30945da8ed370302fb9732eace75" alt="Creating an event" data-path="images/Developer/create-event.png" />

Change the name and update the sample payload as per your requirement and click `Create event`. It is expected that you pass on the data as the `Sample Payload`
while you are triggering this event. This is because, the properties defined in the sample payload can be used as trigger variables inside a workflow.

In the below example, we are using `firstName` defined inside the `Contact` event in a HubSpot workflow.

<img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Developer/event-payload.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=82f2fca2bf6e582db487fde3517f5b06" alt="Using an event payload as a variable" data-path="images/Developer/event-payload.png" />

Now, when you actually trigger the event `Contact`, this workflow will get executed with `name` field consisting of the value sent by you as `firstName` while triggering
the event.

#### Triggering an event.

Refold events can be triggered using various methods. You can make use of the `Event URL`. Go to Settings > Developer > Events

Copy the event URL. Then click on the event that you would like to trigger to get its cURL. See below for reference

<img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Developer/copy-payload.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=9ec094cce71c8cefac3d1c67911cfec8" alt="Setting up event trigger" data-path="images/Developer/copy-payload.png" />

Then you can just make the POST API call with `linked_account_id` and `x-api-key` in the headers

```curl theme={null}
curl --request POST \
  --url https://api.gocobalt.io/api/v1/webhook/64c357c739ec788238ab5f9b \
  --header 'Content-Type: application/json' \
  --header 'linked_account_id: <linked_account_id>' \
  --header 'x-api-key: <x-api-key>' \
  --data '{
        "event": "Add Contact",
        "payload": {
            "first_name": "Subrat",
            "last_name": "Dash",
            "email": "subrat.1108@gmail.com",
            "phone": "7624826260",
            "id": ""
        }
    }'
```

<Warning>
  In the above cURL example, we have not mentioned the `config_id` in the headers. The config id essentially defines the default config with which the worflow shall
  be executed. If `config_id` is not mentioned, Refold considers the `linked_account_id` as the `config_id` by default.
</Warning>

Event URL can be used as a quick resort to trigger an event. If you wish to have better control on triggering such as triggering the worflow executions for a specific application,
instead of for all application workflows with which the event is associated, kindly refer the [REST APIs](https://docs.gocobalt.io/api-reference/event/trigger-an-event-from-your-application) support for events.

To trigger an event from Refold platform so that you can simulate event execution, test workflows and validate the behavior of associated actions, you can use the `Try API` feature of Refold. Refer [here](https://docs.gocobalt.io/ship/tryapi) to learn how you can use Try API.
