How to connect frontend to backend?

Hi, I'm newbie to Octoprint and I'm developing plugin. I want to have button on settings page which should call backend function to find out if Raspberry pi pin is high or low. I've been struggling to find out how to do this for a couple of days, maybe the Blueprint mixin in the backend(?) but not sure how to do it in frontend...

Could you please point me in the right direction? Some examples where something similar is implemented would be great. I'd be even better if you could add such tutorial to documentation.

Thanks community

Here is some of my code.

  • There's a button added to the Files side panel
  • When pushed, it fires off this code in JavaScript which makes an API call back to my own plugin
  • The __init__.py includes SimpleApiPlugin as a mixin for the main class, includes a get_api_commands() function listing what that expects and then has an on_api_command() function which does the work
<div class="gitfiles-trigger accordian-heading-button btn-group"
    data-bind="visible: $root.filesListVisible"><a href="#"
    data-bind="click: gitPull" title="Get latest from github"><i
    class="fa fa-github fa-2"></i></a></div>
1 Like

The SimpleApiPlugin mixin is definitely the way to go. Simplest implementation and easiest to understand for people that don't know Blueprint (like me).

Thanks @OutsourcedGuru that helped quite a lot.

Is the X-api-key header always required when using SimpleApiPlugin?

Only when you are doing it outside of OctoPrint's web interface. If you are doing actions within the web interface, the API calls will just work because your session is already authenticated.

1 Like

Thanks man!