Custom API with form inputs/outputs

Hi there -

I’m in the process of setting up a website with a capacity to perform a calculation for a user. Essentially, the user enters around 15 inputs which need to be fed to a Python function which produces some outputs to be sent back to be displayed for the user.

I’ve looked into using custom APIs to achieve this but have had trouble with the documentation instructions. At the moment I’m just running a basic Flask API with json in/out off of a home server (localhost tunneled to internet). The Flask API takes inputs as POST json data, calls the calculation functions and returns json output.

I’m wondering:

  1. How do I get the inputs into the API call? I have a form set up in Bubble and am sending the values to a database, but cannot work out how to send them anywhere.
  2. How do I read the outputs from the API return? Do they have to go into a database?
  3. Is there a better way to run a Python script through Bubble over an API?

Really simple step by step answers are obviously the dream if anyone has done this before, but any pointers would be great! I’m quite happy to restructure the API if required.

Did you figure this out? I have a similar question.

In case this hasn’t been resolved yet, potential solutions:

  1. Sending input to the API call - when you setup your API with the Bubble API plugin, define the parameters for your API. Make sure to uncheck “Private” as this will allow you to dynamically assign user inputs to the API parameters.

  2. Reading API outputs - this can be done through multiple methods - 1. schedule API to run through a backend workflow and populate a table/update output, 2. Trigger API workflow after a user event and update states/output text fields. You can add a group (or repeating group based on your output data) to capture the output and then specify data type and data source to be API. When you are configuring the API data source, bubble will display the API parameters and default values. Replace the default values with user input fields. Now your API input and output is all configured and user inputs should trigger API output

  3. There are a number of resources online to host your python API. I’ve personally tried PythonAnywhere for an MVP. You could try Heroku or even setup your own through AWS and other cloud services.

Hope this answered your questions.