6

I'm a newbie, I have a project which needs to send daily reminders to users. I see that you can do this using cron jobs. However, I need to call the API which has the daily reminder. This API is an external one. How do I do that?

UPATE: I need to invoke the API and then get the response and send email to users daily.

Mary
  • 127
  • 1
  • 1
  • 8

1 Answers1

11

Curl is your friend. In your case, you would have something like this:

0 8 * * * curl -X POST -d '{"message":"content"}' apidomain.com/endpoint/

In my example, I specify POST even though curl will default to a POST when you specify data (with the -d option). I've included it in case your API expects a different HTTP method like GET or PUT.

The curl manpage will help: https://linux.die.net/man/1/curl

And see this answer for some help with JSON and curl: https://stackoverflow.com/a/7173011/1876622

ubuntugod
  • 592
  • 7
  • 16
HeyZiko
  • 1,660
  • 15
  • 28
  • @Mary, as a follow up to this, you may want to use crontab.guru to confirm your crontab syntax and a 3rd party monitor like wdt.io to ensure you get notified if your cron schedule fails. *Full disclosure: I am involved in both of those projects* – HeyZiko Oct 10 '16 at 21:57
  • thanks for your response! Sorry I didn't make my question clearly as I ought to. I need to invoke the API and then get the response and send email to users daily. How do I do that? – Mary Oct 11 '16 at 01:34
  • You can't retrieve and process the response triggered by a cron job. Cron jobs are like fire and forget. – StandardNerd Jan 21 '23 at 20:36