Having to modify existing code to consume a new asynchronous API call. The original uses cURL to send a request and consume the results. The new method requires me to send an initialisation request, wait 10-20 seconds or until http 200 returns and then send a query cURL and consume the results, but not before checking the status is 'Completed'.
I'm new to looking at cURL, and struggling to get my head around the many post relating to it, any help most welcome. The code is :
function check_boomi($service_id) {
$status="";
Initialize new Northbound API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://testurl.com/init?
ServiceID=".$service_id."");
Wait for http 200 response before running the 'query'
sleep(20);
$result = curl_exec($ch);
Run Northbound API query
curl_setopt($ch, CURLOPT_URL, "http://testurl.com/query?
ServiceID=".$service_id."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Cache-Control: no-cache";
$headers[] = "Postman-Token: d2d57c3e-7c5d-df1b-4b61-dacb6c44b7cg";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
Check result 'status':
If 'Processing' wait 20 seconds and try again
If 'Completed' use the return data
curl_close ($ch);
$data = json_decode($result);
return $data;}