The Old Man Posted October 5, 2020 Posted October 5, 2020 Hello, Does IPS suite have any preferred built-in classes and methods to allow plugins and apps to communicate with third party service REST API endpoints? Thank you.
Daniel F Posted October 5, 2020 Posted October 5, 2020 Could you clarify what you're trying to achieve? We have introduced a Webhook System in 4.5 which could be used for this, but right now it's limited to be used by 3rd party Applications, Plugins and our own Zapier integration. This means, registered web hooks will be able to get a notification with the available data when a specific event happens (e.g. when a member registers, when a topi (or literally any content is created, edited or deleted ) The Old Man 1
Solution bfarber Posted October 6, 2020 Solution Posted October 6, 2020 If you're trying to call a third party REST API, you would just use the built in HTTP libraries we leverage. When I test connecting to our own built in REST API locally I use a test script like so typically <?php $apiKey = 'my-api-key'; require 'init.php'; \IPS\Dispatcher\External::i(); $response = \IPS\Http\Url::external( \IPS\Settings::i()->base_url . '/api/core/members/1' ) ->request() ->login( $apiKey, '' ) ->get() ->decodeJson(); var_dump($response); exit; Zdeněk Tůma and The Old Man 1 1
The Old Man Posted October 10, 2020 Author Posted October 10, 2020 Thank you both, really appreciate the responses. On 10/5/2020 at 5:29 PM, Daniel F said: Could you clarify what you're trying to achieve? Sure, I'm looking to communicate with Cloudflare, AWS REST API, and a couple of other 3rd party services to utilise data in widgets etc. They usually give examples as Curl commands, but I wasn't sure how best to intergrate into IPS. https://api.cloudflare.com/#getting-started-endpoints
bfarber Posted October 12, 2020 Posted October 12, 2020 The heart of it from my answer is $response = \IPS\Http\Url::external( \IPS\Settings::i()->base_url . '/api/core/members/1' ) ->request() ->login( $apiKey, '' ) ->get() ->decodeJson(); The framework will determine if curl is available and use it or fall back to sockets, and there are helper methods to do things like posting, logging in and so on. The Old Man 1
Recommended Posts