fusio icon indicating copy to clipboard operation
fusio copied to clipboard

Need a detailed example for PHP sandbox

Open dlinstedt opened this issue 8 years ago • 2 comments

I would like to use PHP-Sandbox to execute Guzzle.

I want: external call -> action Action -> call another remote REST API using Guzzle or something Process results -> return result of bridged call

Unfortunately I don’t see a way of doing this, and I don’t have access to v8 JS engine, so I can’t use those pieces.

I tried setting up a second service to call a different REST API, but i can’t get it to work with an AUHORIZATION token, so I can’t “hook” two actions together.

I tried leveraging / including Guzzle in the PHP code, and got an error - unable to include it.

Thoughts?

dlinstedt avatar Sep 23 '18 17:09 dlinstedt

Hi Dan, for sure I have just answered on your Google Groups post see: https://groups.google.com/forum/#!topic/fusio/555XNT-wa74

but for a short answer you basically need to:

  1. Create a new HTTP connection
  2. Create a new PHP-Sandbox action and use the following PHP code which uses the configured HTTP connection to send a request:
<?php

/** @var \GuzzleHttp\Client */
$client = $connector->getConnection('my-connection');

$resp = $client->request('GET', '/my/path/', [
    'headers' => [
        'Authorization' => 'Bearer [token]'
    ]
]);


$data = json_decode((string) $resp->getBody());

return $response->build(200, [], $data);

chriskapp avatar Sep 23 '18 17:09 chriskapp

This also can be closed probably

EvoPulseGaming avatar Nov 21 '19 17:11 EvoPulseGaming