Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted October 5, 20204 yr 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.
October 5, 20204 yr 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 )
October 6, 20204 yr Solution 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;
October 10, 20204 yr Author 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
October 12, 20204 yr 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.