mcheah
mcheah

Reputation: 1326

How to set up a scheduled API call on a website?

I'm just learning a little bit about APIs and I just wanted to figure out how I could schedule an API to make a specific call automatically. The situation that I would like to solve is this: I'm using SendGrid to help me to deliver mail from a contact form on my website, but I've been noticing that some emails aren't delivered but are saved on sendgrid's servers for 7 days. I'd like to use their API to save all of the email records into a database on my website so I can review them every so often to find out if there are any that emails that haven't come through.

The only way I know how to do this is to create a website like this:

$records = connection_to_sendgrid_database;
foreach ($records as $record) {
    if ($record->id is not in this database) {
        add the whole record into the database;
    }
}

And then I would have to visit this page every 7 days to make sure I'd get all of the email records.

I'm sure there's a better way of doing this. Unfortunately I don't know much about programming applications that could do it for me, but it seems like automatic API calls must be something that's done all the time. Could someone tell help me to understand how this would normally be done?

Thanks so much for your help!

Upvotes: 3

Views: 1569

Answers (1)

Oka
Oka

Reputation: 26365

Look into Cron jobs for scheduling on Unix-like machines. Any decent web host will offer some kind of cron support.

Manual can be found here.

Example for Monday morning at 0800 hours.

* 8 * * 1 php /path/to/my/script.php

Upvotes: 1

Related Questions