I have created a test function in my REST API (using the SLIM framework) for testing my implementation of a wrapper class for the cloudconvert API.
$app->get('/test', 'authenticate', function() use ($app) {
$response = array();
$converter = new CloudConverter();
$url = $converter->createProcess("docx","pdf");
$response["url"] = $url;
echoRespnse(201, $response);
});
My createProcess function inside CloudConverter class looks like this:
public function createProcess($input_format,$output_format)
{
$this->log->LogInfo("CreateProcess Called");
$headers = array('Content-type: application/json');
$curl_post_data = array('apikey' => API_KEY,'inputformat' => $input_format,'outputformat' => $output_format);
$curl = curl_init(CLOUD_CONVERT_HTTP);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
$curl_response = curl_exec($curl);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
$this->log->LogInfo('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response,true);
return $decoded['url'];
}
I have tested my API using Chrome Advanced Rest Client and i see a successful response from my call to the cloudconvert API but that is not what i was expecting as can be seen in the code above. I was expecting to extract the url and return THAT in my response.
My Questions is: HOW can i extract the url from the response from cloudconvert and return that in my own response.
You need to use
to return response as a string: curl docs.