Need Help Creating My First CRON JOB for Automatic Product Price Updates from an External API

Options

Hello community,

I'm in the process of creating my first CRON JOB and I could use some help. My goal is to automatically update the prices of the products in my database using an external API.

In my database, each product has a unique identifier known as a SKUID. This SKUID is a required parameter for the API request. However, the API allows me to send up to 10 SKUIDs at a time per request.

What I'm trying to do is to get my CRON JOB to fetch all the SKUIDs from my database, group them into batches of 10, send the API request, then update the product prices. I want this process to loop until it has updated all the products in my database.

Any advice on how I could achieve this or examples of similar CRON JOB setups would be greatly appreciated. Also, if there are potential pitfalls or better approaches to this problem, I'm all ears.

Thanks in advance for your help :D

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Hi Steve, the "background task" feature in Xano is a stand-in for "cron" jobs because they can run on a frequent basis. You can wrap a block in a "while" loop that runs "query all records" with a limit of 10 records, and takes in an offset you keep incrementing by 10. That would let you get 10 at a time remit to where they need to go before the loop restarts and gets the next 10. You break the loop when the "query all records" pulls 0 records.

    This kind of more complicated workflow is the kind of "hardest 5%" topic we work on every day in State Change office hours and on our loom-enabled forum.