Mary
Mary

Reputation: 157

How to call API in cron?

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.

Upvotes: 7

Views: 26316

Answers (1)

HeyZiko
HeyZiko

Reputation: 1720

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

Upvotes: 13

Related Questions