I am trying to retrieve the binary file data from a ContentVersion. As i understand it, you get this from making a GET request to the value that is stored in VersionData on ContentVersion. For me it looks like /services/data/v51.0/sobjects/ContentVersion/068Z0000000lxTxIAI/VersionData

My application is a Laravel app and i am using a package called Forrest (https://github.com/omniphx/forrest) to make calls to the Salesforce REST API.

Currently, i am using this code:

$options = [
    'headers' => [
        'Content-Type' => 'application/octet-stream'

$res = Forrest::get('/services/data/v51.0/sobjects/ContentVersion/068Z0000000lxTxIAI/VersionData', [], $options);


The dd() is just for debugging. The $res is just always null. I don't believe it's getting the data. But it's also not failing. I know it's not failing because i can change the value and it fails with an actual exception.

Looking for any help. I'll literally try anything that allows me to retrieve the actual file data from the ContentVersion using PHP.

  • It may be due to the framework or could be down to the integrations contextual user not having the necessary permissions or sharing access. Have you tried enabling debug logs on Salesforce for your integration user?
    – Phil W
    Commented Jun 16, 2022 at 7:08
  • Yea, i don't see anything in the logs at all for it and it looks like it has the right permissions. The package is, at its core, just making a simple get request with passing the auth and content type headers and things. I can tell the package is working, at least, because if i add one character to the get url, it throws an actual exception, but the real url just returns null
    – ryanpitts1
    Commented Jun 16, 2022 at 14:08

1 Answer 1


By default, this package will return the body of a response as either a deserialized JSON object or a SimpleXMLElement object. So, you will need to set default Forrest formatter to none:

$res = Forrest::sobjects('ContentVersion/068Z0000000lxTxIAI/VersionData', ['format' => 'none']);

And you can save the content to a file with:

Storage::put('file.jpg', $res);

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .