Bulk API 2.0 which is the most efficient way to fetch data in range between 2000 and 15000000, doesn't support binary (blob) data in ContentVersion VersionData and it also doesn't support Attachment object at all.
When we try to make a POST callout /services/data/v59.0/jobs/query
with the body of
{
"operation": "query",
"query": "SELECT Id, ContentDocument.LatestPublishedVersionId, ContentDocument.LatestPublishedVersion.Title, ContentDocument.LatestPublishedVersion.FileExtension, ContentDocument.LatestPublishedVersion.FileType, ContentDocument.LatestPublishedVersion.TagCsv, ContentDocument.LatestPublishedVersion.ContentSize, ContentDocument.LatestPublishedVersion.VersionData FROM ContentDocumentLink WHERE LinkedEntityId IN (SELECT Id FROM Opportunity)"
}
an error is returned
also if we try to execute POST callout /services/data/v59.0/jobs/query
with the body of
{
"operation": "query",
"query": "SELECT Id, Body, ParentId FROM Attachment WHERE ParentId IN (SELECT Id FROM Opportunity)"
}
this also returns
400 Bad Request
[
{
"errorCode": "INVALIDJOB",
"message": "Attachment is not a supported object"
}
]
Data Export feature is not an option since it cannot be automated.
Should we try to use Bulk API 1.0 or REST API composite request?
Update: actually we can't even use Bulk API 1.0, it fails with an error
FeatureNotEnabled : Binary field not supported
This document mentions that
The sObject Blob Get resource isn’t compatible with Composite API requests, because it returns binary data instead of data in JSON or XML formats. Instead, make individual sObject Blob Get requests to retrieve blob data.