# External Triggers

The developer API exposes “External” trigger outside of mtion studio. It allows them to be queried as well as fired. This API can be called at [localhost:35393](http://localhost:35393) whenever a local instance of mtion studio is running.

## Get all external triggers

Returns an array of external trigger datas in the currently opened clubhouse

### **URL**

GET <http://localhost:35393/external-trigger/triggers>

### **Response Codes**

| Code          | Description                                                               |
| ------------- | ------------------------------------------------------------------------- |
| 200 OK        | Successfully retrieved the currently opened clubhouse’s external triggers |
| 404 Not Found | No clubhouse open                                                         |

### Sample Query

```
curl -X GET 'http://localhost:35393/external-trigger/triggers'
```

### Sample Response

```json
[
    {
        "id": "1ff84176fc8242d8918e1404f33d6161",
        "name": "New External Trigger",
        "output_parameters": [
            {
                "parameter_index": 0,
                "name": "First String Parameter",
                "data_type": "string"
            },
            {
                "parameter_index": 1,
                "name": "Second Number Parameter",
                "data_type": "number"
            },
            {
                "parameter_index": 2,
                "name": "Third Bool Parameter",
                "data_type": "bool"
            },
            {
                "parameter_index": 3,
                "name": "Fourth Enum Parameter",
                "data_type": "enum"
            }
        ]
    },
    {
        "id": "08195c6a468a49228ccf4c88f11558c7",
        "name": "New External Trigger 2",
        "output_parameters": [
            {
                "parameter_index": 0,
                "name": "First String Parameter",
                "data_type": "string"
            }
        ]
    }
]
```

## Get single external trigger

Returns a single external trigger data specified by id in the currently opened clubhouse

### URL

GET <http://localhost:35393/external-trigger/trigger/:trigger-id>

#### Response Codes

<table><thead><tr><th>Code</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td>200 OK</td><td>Successfully retrieved the trigger data</td><td></td></tr><tr><td>404 Not Found</td><td>No clubhouse open or trigger not found</td><td></td></tr></tbody></table>

### Sample Query

```
curl -X GET 'http://localhost:35393/external-trigger/trigger/1ff84176fc8242d8918e1404f33d6161'
```

### Sample Response

```json
{
    "id": "1ff84176fc8242d8918e1404f33d6161",
    "name": "New External Trigger",
    "output_parameters": [
        {
            "parameter_index": 0,
            "name": "First String Parameter",
            "data_type": "string"
        },
        {
            "parameter_index": 1,
            "name": "Second Number Parameter",
            "data_type": "number"
        },
        {
            "parameter_index": 2,
            "name": "Third Bool Parameter",
            "data_type": "bool"
        },
        {
            "parameter_index": 3,
            "name": "Fourth Enum Parameter",
            "data_type": "enum"
        }
    ]
}
```

## Fire External Trigger

Fires an external trigger with some optional parameter data. When called with GET the data is passed as a query parameter. When called with PATCH the data is passed as a JSON in the body. This request also returns the data of the trigger that was fired.

### URL

GET [http://localhost:35393/external-trigger/fire-trigger/:trigger-id?parameter\_data=\[\]](http://localhost:35393/external-trigger/fire-trigger/:trigger-id?parameter_data=%5B%5D)

PATCH <http://localhost:35393/external-trigger/fire-trigger/:trigger-id>

### Response Codes

| Code          | Description                            |
| ------------- | -------------------------------------- |
| 200 OK        | Successfully fired the trigger         |
| 404 Not Found | No clubhouse open or trigger not found |

### Sample GET Query

```
curl -X GET'http://localhost:35393/external-trigger/fire-trigger/1ff84176fc8242d8918e1404f33d6161?parameter_data=[{"parameter_index":0,"value":"Hello"}, {"parameter_index":1,"value":123}, {"parameter_index":2,"value":true}, {"parameter_index":3,"value":1}]'
```

### Sample PATCH Query

```
curl -X PATCH 'http://localhost:35393/external-trigger/fire-trigger/1ff84176fc8242d8918e1404f33d6161' \
-H 'Content-Type: application/json' \
--data-raw '[{"parameter_index":0,"value":"Hello"}, {"parameter_index":1,"value":123}, {"parameter_index":2,"value":true}, {"parameter_index":3,"value":1}]'
```

### Sample Response

```json
{
    "id": "1ff84176fc8242d8918e1404f33d6161",
    "name": "New External Trigger",
    "output_parameters": [
        {
            "parameter_index": 0,
            "name": "First String Parameter",
            "data_type": "string"
        },
        {
            "parameter_index": 1,
            "name": "Second Number Parameter",
            "data_type": "number"
        },
        {
            "parameter_index": 2,
            "name": "Third Bool Parameter",
            "data_type": "bool"
        },
        {
            "parameter_index": 3,
            "name": "Fourth Enum Parameter",
            "data_type": "enum"
        }
    ]
}
```

## Sample Python script

Below is a sample python script which queries the external triggers in the currently opened clubhouse. It then fires each one while passing some mock data to each of their parameters.

```python
import requests

# This script gets all of the external triggers in the current clubhouse
# It then generates some sample data for each trigger's parameters
# Finally, it fires each trigger using the sample parameter data

def main():
    trigger_datas = get_external_trigger_datas()
    if trigger_datas:
        for trigger_data in trigger_datas:
            sample_parameter_values = generate_parameter_values_for_trigger(trigger_data)
            fire_external_trigger(trigger_data, sample_parameter_values)

# Calls the API to get all the external triggers in the currently opened clubhouse
def get_external_trigger_datas():
    url = "http://localhost:35393/external-trigger/triggers"
    try:
        response = requests.get(url)
        data = response.json()
        response.raise_for_status()
        print(f"Successfully received external trigger datas: {data}")
        return data
    except requests.exceptions.RequestException as e:
        print(f"Error occurred: {e}, {data}")

# Calls the API to fire a trigger
def fire_external_trigger(trigger_data, parameterValues):
    url = f"http://localhost:35393/external-trigger/fire-trigger/{trigger_data["id"]}"
    headers = {'Content-Type': 'application/json'}
    try:
        response = requests.patch(url, json=parameterValues, headers=headers)
        data = response.json()
        response.raise_for_status()
        print(f"Successfully fired external trigger with ID: {trigger_data["id"]}")
        return data
    except requests.exceptions.RequestException as e:
        print(f"Error occurred: {e}, {data}")

# Generates some mock data for each of a trigger's parameters
def generate_parameter_values_for_trigger(trigger_data):
    output = []
    for parameter in trigger_data["output_parameters"]:
        parameterValue = {"parameter_index": parameter["parameter_index"]}
        match parameter["data_type"]:
            case "string":
                parameterValue["value"] = "Sample string from python script!"
            case "number":
                parameterValue["value"] = 123
            case "bool":
                parameterValue["value"] = True
            case "enum":
                parameterValue["value"] = 0
        output.append(parameterValue)
    print(f"Successfully generated mock data for external trigger: {output}")
    return output 

if __name__ == "__main__":
    main()
```

## Clubhouses

The developer API exposes clubhouses of mtion studio. This API can be called at [localhost:35393](http://localhost:35393) whenever a local instance of mtion studio is running.

### Get all clubhouses

Returns an array of clubhouse datas for the current user.

#### **URL**

GET <http://localhost:35393/clubhouses>

#### Response Codes

| Code   | Description                                                               |
| ------ | ------------------------------------------------------------------------- |
| 200 OK | Successfully retrieved the currently opened clubhouse’s external triggers |

#### Sample Query

```json
[
    {
        "id": "MCLB-a294ccd1-70d4-46e1-b37f-d59d4e2f38fe",
        "name": "Kongo's Clubhouse",
        "description": "Your own tropical hide out complete with private beach. Don't worry, there's WiFi.",
        "external_trigger_datas": [
            {
                "id": "518ab1f4ea5d44c18d6a1cc72d964ffb",
                "name": "Sample Trigger 1",
                "output_parameters": [
                    {
                        "parameter_index": 0,
                        "name": "Text Parameter",
                        "data_type": "string"
                    }
                ]
            },
            {
                "id": "8f01945e5a0d46ed8742b663d1cdbe31",
                "name": "Sample Trigger 2",
                "output_parameters": [
                    {
                        "parameter_index": 0,
                        "name": "Number Parameter",
                        "data_type": "number"
                    }
                ]
            }
        ]
    },
    {
        "id": "MCLB-bbe66e6c-f8c4-4ba4-99b7-630b16d09d15",
        "name": "Empty Template",
        "description": "Build your own clubhouse from scratch. Nothing in here but your imagination. ",
        "external_trigger_datas": []
    }
]
```

### Get single clubhouse

Returns the clubhouse data specified by the id.

#### **URL**

GET <http://localhost:35393/clubhouse/:clubhouse-id>

#### **Response Codes**

| Code          | Description                                                               |
| ------------- | ------------------------------------------------------------------------- |
| 200 OK        | Successfully retrieved the currently opened clubhouse’s external triggers |
| 404 Not Found | Clubhouse not found                                                       |

#### Sample Query

```
curl -X GET 'http://localhost:35393/clubhouse/MCLB-bbe66e6c-f8c4-4ba4-99b7-630b16d09d15'
```

#### Sample Response

```json
{
    "id": "MCLB-bbe66e6c-f8c4-4ba4-99b7-630b16d09d15",
    "name": "Empty Template",
    "description": "Build your own clubhouse from scratch. Nothing in here but your imagination. ",
    "external_trigger_datas": []
}
```

### Get active clubhouse

Returns the currently opened clubhouse’s data.

#### **URL**

GET <http://localhost:35393/active-clubhouse>

#### **Response Codes**

| Code          | Description                                                               |
| ------------- | ------------------------------------------------------------------------- |
| 200 OK        | Successfully retrieved the currently opened clubhouse’s external triggers |
| 404 Not Found | No clubhouse open                                                         |

#### Sample Query

```
curl -X GET 'http://localhost:35393/active-clubhouse'
```

#### Sample Response

```json
{
    "id": "MCLB-bbe66e6c-f8c4-4ba4-99b7-630b16d09d15",
    "name": "Empty Template",
    "description": "Build your own clubhouse from scratch. Nothing in here but your imagination. ",
    "external_trigger_datas": []
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mtion.xyz/mtion/developer-api/external-triggers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
