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.

2
  • The same way you would if it was a web page. If you show us how you do that we can confirm that for you
    – RiggsFolly
    Oct 10, 2016 at 16:52
  • Why not send the email upon API call?
    – ozanmuyes
    Jun 20, 2018 at 15:26

1 Answer 1

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

3
  • @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, 2016 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, 2016 at 1:34
  • You can't retrieve and process the response triggered by a cron job. Cron jobs are like fire and forget. Jan 21 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.