Salesforce API

Guide: Retrieving Email Attachments from Salesforce API

This guide outlines the process of retrieving email attachments from Salesforce using APIs. The process is divided into two steps.

Step 1: Fetch Attachments from an Email

The ID to be used in this step can be obtained from CRM Engagement Datal Model.

Use the following API to retrieve the attachments linked to an email:

curl --request POST \
     --url https://api.getknit.dev/v2.0/usecase.execute \
     --header 'Authorization: Bearer <KNIT_API_KEY>' \
     --header 'X-Knit-Integration-Id: <INTEGRATION_ID>' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "useCaseId": "get_attachments_email",
  "data": {
    "body": {
      "id": "ID of the email for which you want to fetch attachments"
    }
  }
}
'

Response Example:

{
  "success": true,
  "data": {
    "attachments": [
      {
        "id": "069J30000099PRaIAM",
        "fileName": "Test Document.docx",
        "createdDate": "2025-02-20T20:20:24.000+0000",
        "fileType": "WORD_X",
        "link": "/services/data/v57.0/sobjects/ContentVersion/068J3000008976bIAA/VersionData"
      },
      {
        "id": "069J30000099PRbIAM",
        "fileName": "Test Document.pdf",
        "createdDate": "2025-02-20T20:20:24.000+0000",
        "fileType": "PDF",
        "link": "/services/data/v57.0/sobjects/ContentVersion/068J3000008976cIAA/VersionData"
      }
    ]
  }
}

Step 2: Download the Attachment

Use the link obtained in Step 1 to download the attachment with the following API:

curl --request POST \
     --url https://api.getknit.dev/v1.0/passthrough \
     --header 'Authorization: Bearer <KNIT_API_KEY>' \
     --header 'X-Knit-Integration-Id: <INTEGRATION_ID>' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "method": "GET",
  "path": "/services/data/v57.0/sobjects/ContentVersion/068J3000008976bIAA/VersionData",
  "encoding": "BASE64"
}
'

Response Example:

{
  "success": true,
  "data": {
    "response": {
      "body": "base64 encoded content"
    }
  }
}

This request will return the file in BASE64 encoding, which can then be decoded for use.