Skip to content

Action Mixin

ActionMixin

Arbitrary "actions" can be called by POSTing data to the /api/action/ endpoint. The POST request must include the name of the action to be performed, and a matching ActionPlugin plugin must be loaded by the server. Arbitrary data can also be provided to the action plugin via the POST data:

POST {
    action: "MyCustomAction",
    data: {
        foo: "bar",
    }
}

Sample Plugin

A sample action plugin is provided in the InvenTree source code, which can be used as a template for creating custom action plugins:

An EXTREMELY simple action plugin which demonstrates the capability of the ActionMixin class.

Source code in src/backend/InvenTree/plugin/samples/integration/simpleactionplugin.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class SimpleActionPlugin(ActionMixin, InvenTreePlugin):
    """An EXTREMELY simple action plugin which demonstrates the capability of the ActionMixin class."""

    NAME = 'SimpleActionPlugin'
    SLUG = 'simpleaction'
    ACTION_NAME = 'simple'

    def perform_action(self, user=None, data=None):
        """Sample method."""
        print('Action plugin in action!')

    def get_info(self, user, data=None):
        """Sample method."""
        return {'user': user.username, 'hello': 'world'}

    def get_result(self, user=None, data=None):
        """Sample method."""
        return True