mtion.xyz
HomeDownload on SteamJoin Discord
  • Getting Started
    • Overview
    • App UI
    • Assets
    • Templates
    • Elements
    • Avatars & NPCs
    • Multi-Player Collaborations
    • Set Up Automated Timelines
    • Set Up Interactions
    • Nodes
    • Play Mode
    • Minigames & Toys
    • Toys Wiki
      • UFO Catcher
      • Space Cat Launcher
      • Score Basket
      • Lucky Cat Dropper
      • Plinko Machines
      • Dice
      • Spinner (Spinning Wheel)
      • Rooftop Riot
    • Build Your Own Clubhouse
  • mtion SDK
    • mtion SDK Documentation
  • FAQ
    • General FAQs
    • mtion app FAQs
    • mtion SDK FAQs
  • Tips & Guides
    • Tips & Tricks
    • Tutorials
  • Developer API
    • External Triggers
  • Livestream Integrations
    • OBS
    • Elgato Stream Deck
    • Vtuber applications
Powered by GitBook
On this page
  • Get all external triggers
  • URL
  • Response Codes
  • Sample Query
  • Sample Response
  • Get single external trigger
  • URL
  • Sample Query
  • Sample Response
  • Fire External Trigger
  • URL
  • Response Codes
  • Sample GET Query
  • Sample PATCH Query
  • Sample Response
  • Sample Python script
  • Clubhouses
  • Get all clubhouses
  • Get single clubhouse
  • Get active clubhouse
  1. Developer API

External Triggers

PreviousTutorialsNextOBS

Last updated 1 year ago

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 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

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

[
    {
        "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

Response Codes

Code
Description

200 OK

Successfully retrieved the trigger data

404 Not Found

No clubhouse open or trigger not found

Sample Query

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

Sample Response

{
    "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

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

{
    "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.

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

Get all clubhouses

Returns an array of clubhouse datas for the current user.

URL

Response Codes

Code
Description

200 OK

Successfully retrieved the currently opened clubhouse’s external triggers

Sample Query

[
    {
        "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

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

{
    "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

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

{
    "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

GET

PATCH

The developer API exposes clubhouses of mtion studio. This API can be called at whenever a local instance of mtion studio is running.

GET

GET

GET

localhost:35393
http://localhost:35393/external-trigger/triggers
http://localhost:35393/external-trigger/trigger/:trigger-id
http://localhost:35393/external-trigger/fire-trigger/:trigger-id?parameter_data=[]
http://localhost:35393/external-trigger/fire-trigger/:trigger-id
localhost:35393
http://localhost:35393/clubhouses
http://localhost:35393/clubhouse/:clubhouse-id
http://localhost:35393/active-clubhouse