General developer forum

Plugin - calling external restful api (Moodle 3+)

 
Picture of Riccardo Proietti
Plugin - calling external restful api (Moodle 3+)
 

I'm new on moodle.

I'd like to create a plugin that calls an external web restful api, read the json data and insert the data on the moodle database.

What kind of plugin type I have to use? Do you think local plugin is the right  choice!

Do you have similar example? 

What's the best way to call an external restful api?

Thank you


 
Average of ratings: -
Picture of Mark Johnson
Re: Plugin - calling external restful api (Moodle 3+)
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

Does your plugin require any user interface? I'm presuming that it's mainly going to be a scheduled task doing the actual importing of data.  A local plugin or admin tool would be suitable for something like this.

Regarding actually calling the webservice, moodle has a "curl" class that wraps PHP's standard curl functions, which should do the job.

 
Average of ratings: -
Picture of Riccardo Proietti
Re: Plugin - calling external restful api (Moodle 3+)
 
Thank you for your reply.

No my plugin doesn't require any user interface. 

So I will use the local plugin.

 (I think I will use moodle-cron to schedule the task)

 
Average of ratings: -
Picture of Hittesh Ahuja
Re: Plugin - calling external restful api (Moodle 3+)
Group Plugin developersGroup Testers

We are approaching this by including a Guzzle HTTP Client (  docs.guzzlephp.org )  to our local plugin that negotiates connections to the REST API and receives /sends any data . 


 
Average of ratings: -