You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Unable to download File Attachment using CURL

Question
21
Views
0
Comments
edited Sep 30, 2019 4:47AM in Integrations and APIs

Content

Hi Everyone,

 

I am stuck in downloading a file attachment from portal using CURL. I am able to get the response but unable to download the attachment. Anyone knows about this or has done this before can help.

 

PFA the code .

 

Thanks

Code Snippet

try{
	if (!extension_loaded('curl')) {
	load_curl();	
	}
	
	
	$org_id = $_GET['org_id'];
	$file_id = $_GET['file_id'];
	
	if((isset($org_id)) && ((strlen($org_id))> 0) && (isset($file_id)) && ((strlen($file_id))> 0))
	{
			//curl call
			$curl = curl_init();

		  curl_setopt_array($curl, array(
		  CURLOPT_URL => "https://thomascookindia.custhelp.com/services/rest/connect/v1.3/organizations/".$org_id."/fileAttachments/".$file_id."?download",
		  CURLOPT_RETURNTRANSFER => true,
		  CURLOPT_ENCODING => "",
		  CURLOPT_SSL_VERIFYPEER => false,
		  CURLOPT_MAXREDIRS => 10,
		  CURLOPT_TIMEOUT => 30,
		  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		  CURLOPT_CUSTOMREQUEST => "GET",
		  CURLOPT_HTTPHEADER => array(
			"Accept: */*",
			"Accept-Encoding: gzip, deflate",
			"Authorization: Basic Uk5UcGFydG5lcl9WaXJ0dW9zQW1hbjpSaWdodG5vdyE=",
			"Cache-Control: no-cache",
			"Connection: keep-alive",
			"Host: thomascookindia.custhelp.com",
			"Postman-Token: 38e507b2-a388-472d-9374-7fab19c2c42b,c7599131-c5c8-44a8-9378-ee95ab601a71",
			"User-Agent: PostmanRuntime/7.17.1",
			"cache-control: no-cache"
		  ),
		));

		$response = curl_exec($curl);
		$err = curl_error($curl);

		curl_close($curl);

		if ($err) {
		  echo "cURL Error #:" . $err;
		} else {
		  echo $response;
		  
		  
		}
			
	}
	
}
catch(Exception $e)
{
	echo $e->getMessage();
}
Tagged:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!