54
Views
9
Comments
How to save api response to Database?
Question

Reactive application

I have an app with: input field (takes in project id) and button ("uploads api response to database")

I think I'm able to successfully get the api response as I have message pop ups and not getting me an error. But how can I confirm the api response? Like to be able to display the response somewhere? or is there a way to print the message somewhere?

My next issue is saving that response to my database. I keep getting data type errors and I'm not sure how to resolve that.. 

Hi,

What ever response you are getting just make that response structure with the database entity in which entity you have to save run its create and update entity action and pass response of the API to that entity source value.

And for the message you can check with the IsSuccess boolean variable is true than use message widget and display whatever on the browser you want to display.

Hope this will help you

Thanks

Ruchi

Hi Alex,

Is your API providing any response output?
If yes then which type of response?
If it is a JSON response then you will need to use JsonDeserialize to track your required variable.
And update your DB accordingly.


Regards,

Hello, 

how do I confirm that my api is providing an output? I place info messages in front and behind my run server action (runs the api get cmd) and I'm not getting any errors. 

Is there a way to display that response output?

You can check your API manually, just navigate and check where you have configured the API and after opening it you will find the "test" button after clicking on that you will get a set of response data.
Or you can debug and check your runtime response.

Yes make a server action and call that API inside it and bind your response output and assign it to server action output and display it any where you want

Thanks

Ruchi

Hello Alex,

Just go through the following discussions it will help you to know how to save data in the database.

It is basically depend on the response you get from the API you can test that in the Test tab.

And then you can use the Create or update action of the entity for saving the records in your DB.

Please go through this dicussions:-

https://www.outsystems.com/forums/discussion/55298/how-do-i-save-data-from-rest-method-to-an-aggregate/

https://www.outsystems.com/forums/discussion/39992/consuming-rest-api-and-add-the-result-to-db/

Hope it helps you..

Regards,

Pavan R

Hello @Alex Chen 

The API response is in List format, so you need to use a for-each loop.

After receiving the current data of the response, you can save the API response to the database.

Here, you can resolve both of your queries by choosing to save or display your response.

Regards 

Nikhil kumar vijay 

Hi Alex,

Step description

1. Create a database table according to the structure you need to receive  information from API.

2. Call api, pass required parameter.

3. Use JSONserialize component and pass the output from API.

4. Assign output of JSONserialize  to entity structure.

5. Save the data into table.


For feedback you can directly pass the response  to feedback message after saving api response.

API_Response Save.PNG
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.