Integration of POST API with Form data as input to the api and saving the api output and form data in a table

I am trying to use the form data as a input to an API( ML model api) to get the output and save the same somewhere. Can anyone help me with this?

Thanks

@Jiban_04 Welcome to the forum
If I am reading your question correctly...

query1 would use the POST with the key/value pairs from the form
you would then store the results {{query1.data}} in a field or a temporary state

Correct @ScottR . How can I implement this? I am stuck in this step

You can add {{query1.data}} into the Default value of a table component.
I would suggest that you read some of the tutorials - they can really help you understand the fundamentals - Create forms using the Form component

Thanks @ScottR I'll look into the same. I'll ask if I have any other doubts

Hi @ScottR. I hope you are doing well. I have some doubt related to SQL Query.

I want to join two tables. Both tables are in two different databases. How can I join the two tables in retool. I tried but it didn't happen

Can you be more specific?
If you have two different databases that is not an issue because you can set up two Resources and still get through the tutorials...

Yeah. It worked. Thanks

one more doubt. Sorry to disturb you @ScottR

I want to save the form data along with the api response in a table as row records. Currently I have set the default value of the column based on api response.

form data is adding successfully but my api response is getting overwrite on all the previous records.

Please see the image

I don't see the API response so it's difficult form me to understand how the table is constructed


these are the form data


this is the response.

I am getting the response in retool also. I just need to insert the record(both form data and response) in table. Everytime I hit the submit button in form it should create a new record.

I hope this will help to understand my concern

OK so your form submits, when that form submits you then have the table displayed from that form data.
Now you take that same form data and hit the SuggestedPriceAPI and the SuggestedPriceAPI gives you back data.

So you have to sets of data:
form data
SuggestedPriceAPI data

Now you want to use ModelAPI to submit both form data AND SuggestedPriceAPI payload data in one query (insert)

Model API submits both SuggestedAPI payload AND form data

Am I correct?

yes. My goal is when I click on submit button, it should insert the formdata input and the output of SuggestedPriceAPI in the table


this is how submit button is and it is using two resources: ModelAPI and Insert query

@ScottR ModelAPI is giving the response. I have added the MODELApi query in form button.

Now, I want to insert the form input and model api output for those inputs in a single row in a table.

This I tried to do using AddRecordQuery.

Suggested Pricing is just the table which I have created using data editor. I need to save the api response and form data in this table.


here is the api response

That looks to be correct.
Can you send me the example data from the form in JSON and the ModelAPI data in JSON so I can test on my end?

Sure.

MODEL API DATA:
{
"Average_Margin_per_MT": 338.0,
"Average_Quantity(MT)": 14.0,
"Customer_segment": "Medium Value Customer",
"Debit_Note_Accepted_Ratio": 0.21,
"Debit_Note_Accepted_Score": 1.0,
"Debit_Note_Ratio": 0.95,
"Debit_Note_Score": 0.0,
"Frequency": 4.06,
"Frequency_Score": 4.0,
"Margin_Score": 3.0,
"Overall_Score": 2.71,
"Quantity_Score": 3.0,
"Recency": 4,
"Recency_Score": 5.0,
"Total_Transactions": 38,
"Transaction_Score": 3.0,
"first_transaction": "False",
"suggested_price": "42.20"
}

FORM DATA:


If you put the form.data in another field and copy the input and paste it that will help. Working from a screenshot will take me longer.
Put {{form.data}} in a field and then click onto it and you can copy it and paste it

Sure @ScottR

buyer_price "45"
item_name "PET Bottle Scrap Baled - Clear"
listing_quantity "40000"
logistic_cost "20000"
max_margin "3"
min_margin "1"
seller_id "324"
seller_state "Telangana"
seller_zone "Southern Zone"

@ScottR any update on this? Let me know if you need any more information or data

So looking at the Add Record screenshot, that seems to be fine, but this might be the issue "I have added the MODELApi query in form button."
I think you are trying to hit ModelAPI and Submit the form (Add new record) at the same time.
You should run the ModelAPI first and allow that to be captured in AddRecord then as the user fills out the form you should get the other information.

Also, if you want to combine all of the data together you can do the following (Note that I am writing everything out - it's really the var combinedData line that matters: Also, some of the numbers below are either strings or ints but I don't know your table setup so all of the numbers could be either an int or string.)

Create a new Javascript query and call it combinedData and put the following in it:

var formData = [{"buyer_price":"45",
"item_name":"PET Bottle Scrap Baled - Clear",
"listing_quantity": 40000,
"logistic_cost": 20000,
"max_margin":3,
"min_margin":1,
"seller_id":324,
"seller_state":"Telangana",
"seller_zone:":"Southern Zone"
}]
var modelAPIData = [{
"Average_Margin_per_MT": 338.0,
"Average_Quantity(MT)": 14.0,
"Customer_segment": "Medium Value Customer",
"Debit_Note_Accepted_Ratio": 0.21,
"Debit_Note_Accepted_Score": 1.0,
"Debit_Note_Ratio": 0.95,
"Debit_Note_Score": 0.0,
"Frequency": 4.06,
"Frequency_Score": 4.0,
"Margin_Score": 3.0,
"Overall_Score": 2.71,
"Quantity_Score": 3.0,
"Recency": 4,
"Recency_Score": 5.0,
"Total_Transactions": 38,
"Transaction_Score": 3.0,
"first_transaction": "False",
"suggested_price": "42.20"
}

]
var combinedData = formData.concat.apply(modelAPIData);
return combinedData

Now create a new table component and populate the Data field with {{combinedData.data}}