Skip to content

API Mixin

APICallMixin

The APICallMixin class provides basic functionality for integration with an external API.

Sample Plugin

The following example demonstrates how to use the APICallMixin class to make a simple API call:

A small api call sample.

Source code in src/backend/InvenTree/plugin/samples/integration/api_caller.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin):
    """A small api call sample."""

    NAME = 'Sample API Caller'

    SETTINGS = {
        'API_TOKEN': {'name': 'API Token', 'protected': True},
        'API_URL': {
            'name': 'External URL',
            'description': 'Where is your API located?',
            'default': 'reqres.in',
        },
    }
    API_URL_SETTING = 'API_URL'
    API_TOKEN_SETTING = 'API_TOKEN'

    def get_external_url(self):
        """Returns data from the sample endpoint."""
        return self.api_call('api/users/2')