I was able to resolve this error (which I was having with a workflow field) by applying Patch #6 from this issue: https://www.drupal.org/project/entity/issues/2819665 π¬ EntityMetadataWrapperException: Unknown data property Fixed
https://www.drupal.org/files/issues/entity-metadata-wrapper-exception-11... β
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);
?>
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);
?>
DarrellDuane β made their first commit to this issueβs fork.
I have the same requirement, any tips?