Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call API in cron?

Tags:

php

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.

like image 229
Mary Avatar asked Oct 10 '16 16:10

Mary


1 Answers

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

like image 119
HeyZiko Avatar answered Oct 05 '22 22:10

HeyZiko