Is it possible to somehow catch a callback from an external API after executing a file.create:after hook within the panel without the need of a whole field-extending plugin?
In detail:
After a file(s) has/have been created its URL will be sent to a some other website which fetches and copies the file it automatically to their server. I can probably send this URL to the the other website inside the file.create:after hook easily (I guess) via regular PHP.
However I’d like to append an indicator somewhere in the panel that the file(s) has/have successfully been fetched by the other page. And therefore need to catch their API callback.
So, the best case would be:
–> file.create:after hook fired after file(s) has/have been created in a files field/section
–> append spinning indicator somewhere in panel
–> other website sends API callback that it finished fetching/copying the file(s)
–> catch that callback in the panel
–> replace spinner with checkmark or something in panel
The hook runs server-side, so you cannot make any changes to the frontend from such a hook. The only thing you can do from a hook, is throw an exception, which could also be a success message.
Ah ok thx!
If you may:
• would the success message be formatted like the native modal overlay or something else?
• is it possible to catch the API response from the other server within the hook or do you maybe know of another way to catch the response?
hm yeah, but I don’t really get how to process the response :
return [
'hooks' => [
'file.create:after' => function ($file) {
// the servers credentials
require_once('someapi.php');
$someAPIconnection('my_key', 'my_secret');
// url to be fetched
$params['url'] = 'theuploadedfiletothepanel.mp4';
// fetched successfully (or maybe not)
$response = json_encode($upload/$responseInfo);
// display $response as panel modal overlay but don't really know how since the lack of skills
something $response;
}
]
]
EDIT: Also I guess, the file.create:after hook is not really waiting for the response or? If the response of a successful fetch is 30 seconds after the file creation, the hook won’t process the response any more, no?
Sorry, deleted it. It’s more like require_once('/path/to/jwplatform-php/init.php'); $api= new Jwplayer\JwplatformAPI('INSERT API KEY', 'INSERT API SECRET');
which is to communicate with their API
It’s actually this library which is supposed to give easy access to their API:
Ah ok thx, I’ll see if this is within the range of my skills otherwise I’ll post it in the Jobs section I guess.
Before I try though two questions:
• would the file.create:after hook also throw the exception, say 30 seconds, after creating the file. Because the fetching by the other server might take some time and therefore also the other server’s response.
• is the exception displayed as regular modal overlay like all the other modal overlays?