API commands examples for CURL / Bitfocus Companion

I try to use Octoprint with Elgato Stream Deck.
I did install Bitfocus Companion on Raspberry Pi where Octoprint is installed too.

I'ts hard to find a complete API command and to figure it out if this may work.
I did create an API key and activated CORS but i have no luck to see any API requests in octoprint.log
I found a great documentation about API-Commands but no examples for using it with curl or any other applications.
Anyone have a complete curl command or how to know to use it with Bitfocus Companion?

BTW: Swagger-UI for Octoprint would be helpful too.

Thanks for help,

Best regards,
Webfeger

You aren't going to find many examples of using the API with curl because it's really more of a question of how to use curl at that point. You just need to supply the appropriate headers and information with the request, just like you would for any HTTP request, as the API describes.

For a simple GET request, you'd supply your apikey (someapikey) in the header:

$ curl -H "X-Api-Key: someapikey" http://octopi.local/api/server
{"safemode":null,"version":"1.7.2"}

For other methods, you specify the method, along with your data and it's type (always going to be json for the OctoPrint api). This sends a command to the PSU Control plugin to turn the PSU ON:

$ curl -X POST -H "X-Api-Key: someapikey" -H "Content-Type: application/json" -d '{"command":"turnPSUOn"}' http://octopi.local/api/plugin/psucontrol

As far as working with other applications, it will follow the same concepts.

couple curl with jq and you can have all kinds of fun :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.