Help with external API save to database through timer/business logic

Backendless Version Online

Client SDK REST

Application ID 41F831D7-1082-9EE4-FF6C-0E7ED3481C00

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. call an external API through a timer (which will eventually run once a week)
  2. save data to database from that api call

Actual Behavior

Please provide a description of what actually happens, working from the same starting point.

Be descriptive: “it doesn’t work” does not describe what the behavior actually is – instead, say “the request returns a 400 error with message XXX”. Copy and paste your logs, and include any URLs.

  1. External API is called
  2. I know the data is being provided by the external api but cant save the body/data elements provided by api.


this is the response, but I can only seem to save the “date_last_run” “date_last_run_timestamp” “name” and “url” to the database using this method:

i have tried to get the property of the “data” elemtn of the json response but it doesnt pull the detail through and save to the database.

Any ideas or suggested tutorials to watch would be greatly appreciated.

1 Like

Hi, @Andrew_Billcliffe

Try to create the column “data” JSON data type in the “awrstest” table before making a request.
Try this logic:

Result I got:

Is this the result you you were looking for?

Regards,
Marina

That’s closer than I got! Thank you, but I actually need a column for each of the fields in the data element of the API response which is what my Bubble app does just now but I find bubble very slow so trying out Backendless after some recommendations.
I’m trying to get all 29 fields of the data response into their own columns.

Hi Andrew,

To do this, extract the value of the data property from the response and pass the resulting object into the Save Object in Backendless block. Please let us know if that approach works for you.

Regards,
Mark

Thanks Mark. I played around with a few things and truth be told i was a little lost but found a very similar topic and your advice on this thread was a huge help! How to get an object from a nested array of objects using Codeless - #7 by Andreas_Marinopoulos

Proof of concept below, just need to build a few blocks to write it to the database now. Any critique on my method?

Its a big learning curve but I’m really beginning to enjoy Backendless!

Hi @Andrew_Billcliffe,

I would do it in the following way, but yours is also good:

Its a big learning curve but I’m really beginning to enjoy Backendless!

Great to hear it!

Regards

Interesting, thanks Stanislaw. Looks like there is potentially less processing involved in your method and potentially faster/easier to execute in the server?

I don’t think there will be any noticeable difference in performance here. The code will execute very quickly, and 99.9% of the execution time will be taken by a request to a third-party API in your HTTP/s block. The only difference I wanted to show is the ability to use fewer blocks without losing readability, thus reducing the number of things that you, as a developer, need to support in the future.

1 Like

Hi @Stanislaw_Grin

I’m a newbie who has a case similar to Andrew’s, the timer runs as expected but doesn’t save any data at all.
image

APP ID : 78ACB4A5-CEFB-69CC-FF5A-07DE08653500
Please advice and guidance I would really appreciate.

Hi @lant,

have you tried to log the HTTP/s response and see what value it returns?
You can use the print block for this purpose.

Thanks for your fast response, actually i also try to extract the list of data from this api https://sheetdb.io/api/v1/vzbboolwx9aot and below is log

i’m sorry i don’t know about print block

This is the print block. It logs a message in the log file:

Hi Mark,
Thank you for showing it but I still don’t understand how to use it, I tried like the following image but I’m not sure if i’m doing something right because I don’t know what value to input.

image

You can print anything that will facilitate solving the problem. I don’t quite understand what the problem is, but with the print block you can have a way for the logic you create to report it’s state (variables, service responses, etc) back to you via logging.

Okay mark, I’ll try to explain again the problem I’m having, so I’m trying to periodically fetch data from the external api and store it in a table.
I’ve tried to make codeless logic like above but no data goes to the table except the default backendless column. The External API is https://sheetdb.io/api/v1/vzbb00lwx9aot
and logs looks like this


I hope it helps to find a solution, thank you.

The link for the API returns a JSON array. How should the data in that array be mapped to a table in database?

1 Like

it’s true that the data is in an array, that’s the problem, I’m confused about how to map the data to a table. I need help and advice because I really don’t know about this yet.

Well, one possibility is to store each object in the array as a separate object. In that case, the Bulk Create block would do the job:

Great, it worked successfully!
Thank again Mark…