Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| indigo_2025.2_documentation:plugin_guide [2026/05/04 15:04] – [Request] davel17 | indigo_2025.2_documentation:plugin_guide [2026/05/04 23:49] (current) – [Plugin] davel17 | ||
|---|---|---|---|
| Line 1557: | Line 1557: | ||
| * If for some reason you can't include the header, you may pass the API key as an additional GET argument on the URL ('' | * If for some reason you can't include the header, you may pass the API key as an additional GET argument on the URL ('' | ||
| + | Plugin API scripting can be a great way to add useful features to your plugin. For example, you could create a path for an external script to communicate with your plugin to provide status information or fire a trigger. We have provided a complete example below. | ||
| ==== Request ==== | ==== Request ==== | ||
| As a reminder, here's how you specify an action in Actions.xml that is used only via an API (from another plugin such as the IWS plugin): | As a reminder, here's how you specify an action in Actions.xml that is used only via an API (from another plugin such as the IWS plugin): | ||
| Line 1565: | Line 1566: | ||
| </ | </ | ||
| </ | </ | ||
| - | Notice that the '' | + | Notice that the '' |
| Here's how an action method is defined in your plugin: | Here's how an action method is defined in your plugin: | ||
| Line 1640: | Line 1641: | ||
| For long-running actions, one pattern would be to reply immediately with some kind of acknowledgement of the incoming message, then handle the processing asynchronously. As this approach would complete the HTTP request/ | For long-running actions, one pattern would be to reply immediately with some kind of acknowledgement of the incoming message, then handle the processing asynchronously. As this approach would complete the HTTP request/ | ||
| + | === Examples === | ||
| + | Here is a generic example that includes all the necessary parts of a plugin API interaction. | ||
| + | |||
| + | == Plugin == | ||
| + | Your plugin needs to define an Indigo Action to receive the data. | ||
| + | |||
| + | < | ||
| + | <Action id=" | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Your plugin needs to define a callback method to do something. | ||
| + | |||
| + | < | ||
| + | def handle_some_action(self, | ||
| + | some_value = action.props[" | ||
| + | some_other_value = action.props[" | ||
| + | | ||
| + | # the reply must be valid JSON or an indigoDict() object | ||
| + | reply = indigo.Dict() | ||
| + | reply[" | ||
| + | reply[" | ||
| + | return some_result | ||
| + | </ | ||
| + | |||
| + | == The Request == | ||
| + | The caller needs to construct a valid request. | ||
| + | |||
| + | < | ||
| + | import httpx | ||
| + | |||
| + | MY_API_KEY = " | ||
| + | MY_REFLECTOR = " | ||
| + | PLUGIN_ID = " | ||
| + | ACTION_ID = " | ||
| + | |||
| + | # The payload must be valid JSON. The API does not support binary encoding and payloads should be of a reasonable size. | ||
| + | payload = { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | |||
| + | my_url = " | ||
| + | response = httpx.get(my_url, | ||
| + | |||
| + | print(f" | ||
| + | print(f" | ||
| + | </ | ||
| + | |||
| + | '' | ||
| ===== Event and Message Flow ===== | ===== Event and Message Flow ===== | ||
| Under some circumstances, | Under some circumstances, | ||