Get Files

Purpose

To fetch a file using its encrypted ID.

Endpoints

Request Details

Request URL

{api-domain}/crm/{version}/files

Header

Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52

Scope

scope=ZohoCRM.Files.{operation_type}

Possible operation types

READ - To retrieve files from ZFS

Parameters

Possible Errors

  • INVALID_URL_PATTERNHTTP 404

    Please check if the URL trying to access is a correct one
    Resolution: The request URL specified is incorrect. Specify a valid request URL. Refer to request URL section above.

  • OAUTH_SCOPE_MISMATCHHTTP 401

    Unauthorized
    Resolution: Client does not have ZohoCRM.Files.READ scope. Create a new client with valid scope. Refer to scope section above.

  • NO_PERMISSIONHTTP 403

    Permission denied to read
    Resolution: The user does not have permission to read files. Contact your system administrator.

  • INTERNAL_ERRORHTTP 500

    Internal Server Error
    Resolution: Unexpected and unhandled exception in Server. Contact support team.

  • INVALID_REQUEST_METHODHTTP 400

    The http request method type is not a valid one
    Resolution: You have specified an invalid HTTP method to access the API URL. Specify a valid request method. Refer to endpoints section above.

  • AUTHORIZATION_FAILEDHTTP 400

    User does not have sufficient privilege to read.
    Resolution: The user does not have the permission to read files. Contact your system administrator.

Sample Request

Copiedcurl "https://www.zohoapis.com/crm/v2.1/files?id=2cceafa194dxxxxxxxx4a20ed2"
-X GET
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
4.0.04.x
Copied//Get instance of FileOperations Class
$fileOperations = new FileOperations();
//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();
$paramInstance->add(GetFileParam::id(), $id);
//Call getFile method that takes paramInstance as parameters
$response = $fileOperations->getFile($paramInstance);
Copied<?php
class GetFiles{
    
    public function execute(){
        $curl_pointer = curl_init();
        
        $curl_options = array();
        $url = "https://www.zohoapis.com/crm/v2.1/files?";
        $parameters = array();
        $parameters["id"]="f46166fa14ce16c6e2622b3ce8283075efea966da0bddc9edf7421c6bb22cc17";
        
        foreach ($parameters as $key=>$value){
            $url =$url.$key."=".$value."&";
        }

        $curl_options[CURLOPT_URL] = $url;
        $curl_options[CURLOPT_RETURNTRANSFER] = true;
        $curl_options[CURLOPT_HEADER] = 1;
        $curl_options[CURLOPT_CUSTOMREQUEST] = "GET";
        $headersArray = array();
        $headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
        
        $curl_options[CURLOPT_HTTPHEADER]=$headersArray;
        
        curl_setopt_array($curl_pointer, $curl_options);
        
        $result = curl_exec($curl_pointer);
        $responseInfo = curl_getinfo($curl_pointer);
        curl_close($curl_pointer);
        list ($headers, $content) = explode("\r\n\r\n", $result, 2);
        if(strpos($headers," 100 Continue")!==false){
            list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
        }
        $headerArray = (explode("\r\n", $headers, 50));
        $headerMap = array();
        foreach ($headerArray as $key) {
            if (strpos($key, ":") != false) {
                $firstHalf = substr($key, 0, strpos($key, ":"));
                $secondHalf = substr($key, strpos($key, ":") + 1);
                $headerMap[$firstHalf] = trim($secondHalf);
            }
        }
        $response = $content;
        if ($response == null && $responseInfo['http_code'] != 204) {
            list ($headers, $content) = explode("\r\n\r\n", $content, 2);
            $response = json_decode($content, true);
        }
        $contentDisp = $headerMap['Content-Disposition'];
        $fileName = substr($contentDisp, strrpos($contentDisp, "'") + 1, strlen($contentDisp));
        
        if (strpos($fileName, "=") !== false)
        {
            $fileName = substr($fileName, strrpos($fileName, "=") + 1, strlen($fileName));
            
            $fileName = str_replace(array(
                '\'',
                '"'
            ), '', $fileName);
        }
        $filePath = "/Users/test/PHP/PHPNativeSampleCode/";
        $fp = fopen($filePath . $fileName, "w"); // $filePath - absolute path where downloaded file has to be stored.
        $stream = $response;
        fputs($fp, $stream);
        fclose($fp);   
        
    }
    
}
(new GetFiles())->execute();
2.1.0
Copied# Get instance of FileOperations Class
fo = Files::FileOperations.new
# Get instance of ParameterMap Class
pm = ParameterMap.new
# Add the id to ParameterMap instance
pm.add(Files::FileOperations::GetFileParam.id, 'f46166fa14ce16c6e2622b3ce8283075a4aeb9c355b109cd8f502c78ffdb9324')
# Call get_file method that takes ParameterMap instance as parameter
response = fo.get_file(pm)
Copiedrequire 'net/http'
require 'json'

class GetFiles 

    def execute
        parameters ={}
        parameters["id"]="f46166fa14ce16c6e2622b3ce8283075efea966da0bddc9edf7421c6bb22cc17"
        query_string = parameters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join('&')
        url= "https://www.zohoapis.com/crm/v2.1/files"
        url += '?' + query_string if !query_string.nil? && (query_string.strip != '')
        url = URI(url)
        req = Net::HTTP::Get.new(url.request_uri)
        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        headers={}
        headers["Authorization"]="Zoho-oauthtoken 1000.dfa7XXXXXXXXXXXXXXXXXX84f9665840.c176aeXXXXXXXXXXXX13f3d37a84d"
        headers&.each { |key, value| req.add_field(key, value) }   
        
        response=http.request(req)
        file_name = response.to_hash["content-disposition"][0].split('=')[1]

        file_name = file_name.split("''")[1] if file_name.include? "''"

        file_name = file_name.gsub('"', '') if file_name.include? '"'

        status_code = response.code.to_i
        headers = response.each_header.to_h
        print status_code
        print headers
        unless response.body.nil?
            File.open("/Users/test/RUBY/RUBYNativeSampleCode/"+file_name, 'w') { |file| file.write(response.body) }
        end
    end
end
GetFiles.new.execute
Copiedresponse = invokeurl
[
	url: "https://www.zohoapis.com/crm/v2.1/files?id=2cceafa194dxxxxxxxx4a20ed2"
	type: GET
	connection:"crm_oauth_connection"
];
info response;