- πΊπΈUnited States darrellduane
I was able to retrieve a file from the ContentVersion object using PHP and cURL with this code snippet. It is using the Drupal 7 Salesforce Suite module.
<?php $fullUrl = 'https://test.sandbox.my.salesforce.com/services/data/v60.0/sobjects/ContentVersion/' . $salesforce_entity_id . '/VersionData'; $accessToken = $sfapi->getAccessToken(); // Use cURL to make the GET request $ch = curl_init($fullUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $accessToken, 'Content-type: application/json', )); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects curl_setopt($ch, CURLOPT_FAILONERROR, true); // Report HTTP code > 400 as error curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Do not verify SSL certificate curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return the transfer as a string $image_data = curl_exec($ch); $directory = 'private://imagefiles/'; $uri = $directory . basename($title) . '.' . $filename; // Set the filename // Save the file data to the specified location $saved_file = file_save_data($image_data, $uri, FILE_EXISTS_REPLACE); // Save the file to the Drupal file system // $saved_file = file_save($file); // Check if the file was saved successfully if ($saved_file) { drupal_set_message("The file has been saved successfully."); } else { drupal_set_message("There was an error saving the file.", 'error'); } // Check for errors if (curl_errno($ch)) { $error_msg = curl_error($ch); ds($error_msg, 'cURL Error'); } // Check if the request was successful and write the file curl_close($ch); ?>