I have an AWS lambda function, which helps me parse a PDF document to extract relevant data and fill a Salesforce object with this data afterwards in a Salesforce flow. I have a running setup, performing a HTTP POST callout using a pure (manually created) apex class and I would like to switch to the new Flow HTTP Callout element.
TL;DR
How can I pass a ContentVersion.VersionData base64 encoded blob of a pdf file to a Flow HTTP POST callout?
Apex approach
Using a ContentDocumentLink object (describing a PDF file / attachment linked to another object (e.g. a Case)) with a ContentDocumentId variable I retrieved a ContentVersion object by matching the ContentDocumentId on this object.
I pass this ContentVersionId of the ContentVersion object to an apex class, which retrieves the base64 encoded Blob of the PDF object like so
public static Blob get_content_version_blob_data(String ContentVersionId ) { Blob pdfblob = [SELECT VersionData FROM ContentVersion WHERE Id = :ContentVersionId].VersionData; return pdfblob;}I then create the HttpRequest, performing the callout and get the response.
HttpRequest request = new HttpRequest();request.setEndpoint(<my_endpoint_url>);request.setMethod('POST');request.setHeader('Content-Type', 'pdf');request.setHeader('Accept-Charset', 'UTF-8');request.setBodyAsBlob(pdfblob);Http http = new Http();HttpResponse response = http.send(request);Map<String, Object> d_response = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());This approach is working perfectly fine, but with manual apex coding.
Hence I tried to transfer it to the new Flow HTTP Callout method.
Flow HTTP Callout approach
I created a simple flow with the following steps
- Get ContentVersion
- Retrieves the ContentVersion object, based on a match of the ContentDocumentId
- The output is stored in a ContentVersion object named CurrentContentVersion, storing the variables ID (ContentVersionId) and VersionData (assumed to hold the blob data, as seen in the apex code)
- Set callout body variable
- The callout_body.body variable is assigned as the CurrentContentVersion.VersionData
- Execute the HTTP Callout
- As described in salesforce help Configure an HTTP Callout Action I created a new variable callout_body, using the Apex-Defined data type and referencing the automatically created apex class ExternalService__MyService_CalloutMyService_IN_body for my callout input body.
- Note that in the JSON schema the request body of my ExternalService is defined as string
- Assign the response to my local variables
JSON schema for request body in ExternalService
[...],"requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "body": { "type": "string" } } } } }, "required": true},[...]Here are some screenshots of my flow
This approach already fails at step 2, assigning the callout_body.body variable with error message
Error Occurred: Value of class core.filemanager.FileBlobValue is not a ValueType: STRING
I can relate to this error message, since my JSON schema describes the body as type string. Hence I tried to change the JSON schema to type object for the body like
[...]"body": { "type": "object"}[...]But doing this, I cannot select the apex class ExternalService__MyService_CalloutMyService_IN_body any more for my callout_body input variable (see step 3), only the *_OUT_2XX and *_OUT_2XX_data options are available.
Same behaviour / issue when trying a binary input format for the body
[...]"body": { "type": "string", "format": "binary"}[...] Final question
Has anyone managed to define a blob style base64 encoded object type for the input body of a Flow HTTP POST callout to pass the blob to the external service?
Any help is very appreciated, thanks!
request body can be send as blob using this component inside flow-:
https://unofficialsf.com/no-code-web-callouts/
Another option is to Send content Id from flow as request parameter, and use Callback to pass pdf blob
