Import SQL data into Xano with cURL and PHP CRON

Options

Good morning,
I have a "Launch" plan
I have a MySQL database at a NUXIT host
I'm coding PHP pages that show me the JSON of each table (40 tables)
I would like to create 40 PHP CRON which would allow me to update my XANO database every day (or every hour).

I need this because we have created a Web application for our customers which allows them to have an activity dashboard on their consumption of appointments with our psychologists.

For the moment we don't need to write to the XANO database. Just to recover the data from our mySQL database while we were redoing our entire intranet with Weweb.

Do you have a CURL code that would allow us to go faster?
I've been trying to do this for 3 days but it doesn't update the data in XANO.
I'm trying with only 1 table in my workspace: "Intranet AM - ISO PROD"

thank you for everything

Answers

  • axismundi
    axismundi Member
    Options

    Finally, thanks to a youtube video I managed to create a "Task" in Xano which deletes my test table every and updates it thanks to my API

    I don't know if it's good to delete 40 tables every day and rewrite in them every day, it's probably not the right solution.
    I would have preferred to update the existing data and make a condition that only updates the data that has a field: "modified_at" > Day - 2 but I don't know how to do that!
    If you have the solution

    Thanks for all

  • Lefteris - blupry.com
    Options

    Hello @axismundi,

    It is definitely not a good practice to delete that many tables and just add the new data. Sooner or later some exception will happen and lose the data.

    From what I understand, none of your tables are hosted on Xano (something that would really make the process easier).

    Since they are on a mysql DB, I would suggest adding a Direct Database Query (https://docs.xano.com/working-with-data/functions/database-requests/direct-database-query) that would retrieve the modified_at field. I am guessing that field is in a Unix Format.

    After that you can create a variable that will return the current timestamp, using the to_timestamp filter like this:

    Note: Make sure you use the same timezone your DB is using.

    After that the only thing that is left is comparing the two timestamps (the one that is returned from the modified_at field, alongside the current one return by the variable), and if the difference between them is larger than the 48 hours (172800 seconds to match the timestamp format), update the record.

    All of these steps should be included inside the implementation of your programmed task.

    Hope that helps!