How can I get the API connection details to retrieve my organization's files, attachments, PDFs and other files stored in SalesForce?
#Trailhead #Salesforce Developer #Salesforce Admin
Hey Regine,
To retrieve files (ContentVersion, ContentDocument, Attachment) via API, here's the actual path:
1. Set up a Connected App (Setup > App Manager > New Connected App), enable OAuth Settings, note the Consumer Key/Secret, this is what your external tool authenticates with.
2. Authenticate using OAuth 2.0 (Web Server Flow for a server-side app, or Username-Password Flow for quick testing, though that's being phased out). This gives you an access token and instance URL.
3. Query file metadata via REST API:
- For files uploaded through Lightning (Files feature): query ContentVersion (has the actual file body in VersionData) and ContentDocumentLink (to find which records a file is attached to)
- For older Attachments (Classic-style, still exist on many orgs): query the Attachment object directly, it has a Body field with the binary content
4. To actually download the binary content, hit the REST API endpoint:
`GET /services/data/vXX.0/sobjects/ContentVersion/{Id}/VersionData` (for Files)
`GET /services/data/vXX.0/sobjects/Attachment/{Id}/Body` (for classic Attachments)
with your Bearer access token in the header.
If you're just testing/exploring rather than building an integration, Workbench (
workbench.developerforce.com) lets you browse and download files directly through a UI without writing code, useful for a quick one-off pull.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_get_attachment_body.htm