Skip to main content

#HTTP POST Method0 utenti parlano di questo argomento

T H ha fatto una domanda in Flow HTTP Callout

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

  1. 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)
  2. Set callout body variable
    • The callout_body.body variable is assigned as the CurrentContentVersion.VersionData
  3. 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
  4. 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 flowPass PDF blob via HTTP Post Callout

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!

5 risposte
0/9000

Sábado chegou, mas só penso na quarta feira, quandk nosso Breakfast And Learn Flow se iniciará as 09h e faremos uma integração ao vivo para extrair informações de CNPJ diretamente para o Salesforce, um clássico data mining em ação se código, utilizando apenas FLOW.

https://trailblazercommunitygroups.com/events/details/salesforce-salesforce-admin-group-vitoria-brazil-presents-consulta-de-cnpj-com-salesforce-flow-6-breakfast-and-learn-flow/Sábado chegou, mas só penso na quarta feira, quandk nosso Breakfast And Learn Flow se iniciará as 09h e faremos uma integração ao vivo para extrair informações de CNPJ diretamente para o Salesforce, u#Sales Cloud #Integration #Flow #Salesforce Developer #Automation #Analytics #HTTP Callouts #HTTP POST Method #HTTP Header
0/9000

Hello,

 

I am using Open API 3.0 to connect two Salesforce orgs. I have a scenario where,

 

Let's say

  1. Source Org Account Name : Salesforce, USA
  2. Target Org Account Name: Salesforce, USA

There is a duplicate rule in Target Org which doesn't allow us to create the accounts with the same names.

 

So, when I tried to push the source org record to Target org and I got the error as ( 400 response code)

Result: [{

"message_set" : true,

"message" : "Please choose one of these records instead.",

"errorCode_set" : true,

"errorCode" : "DUPLICATES_DETECTED"

}]

My questions are,

  1. Is there anyway to get extract message only from the response?
  2. Is there anyway to get the duplicate record Id from the Target org which I can update the Id back to one of the Account's fields in source org?

The response result doesn't return any details apart form the above message so that makes hard for me to refer the target org accountId.

Thank you in advance.

#HTTP POST Method #Httpcallout #Flow

2 risposte
  1. 14 ago 2023, 19:57

    I was able to capture the message details separately. 

    So, the general Variable/Formula fields won't support to do it. So I created a text template field to capture the data and applied some formula functions to extract the details that I was looking for.

     

    It would be better if Salesforce allows us to store these details in a formula field directly and use it for screen flows.

     

    Any idea on point 2?

0/9000

Hello,

 

I started to use the Open API 3.0 to connect Salesforce with Salesforce by using flows. I am successfully able to post the records from source to target org.  Now, I want to continue with record update process.

It means, let's say I created a Contact record from Source org to Target Org and now I want to update a field value between these orgs. As per today, flows doesn't support the patch operation. With Winter'24 release flows will provide option to use the Patch action as well.

 

With this, do I have to rework anything in my current setup/ how to use the patch action concept with open API's?

 

Thanks in advance

#OpenAPI #Flow #HTTP POST Method

0/9000
Subhani Pothakamuri ha fatto una domanda in Flow HTTP Callout

Hi,

 

I am trying to use the Http post action to post a request to external system. There is a change request from external system that I need to add one more parameter in my json request. Currently I do not see any option to edit the sample request json apart from doing it from scratch. Any idea on if we already have any option for this?

#HTTP POST Method #Screen Flow

 

Ex: current http request

{

"email":"testusers@testing.com",

"apikey":"xxxxxxxxxxxxxxxxx"

}

Updated 

 

{

"email":"testusers@testing.com",

"apikey":"xxxxxxxxxxxxxxxxx"

"name":"testing"

}

5 risposte
  1. 30 giu 2023, 21:01

    It turn out that it may be a bug from salesforce end and they will investigate on this and confirm the outcome. As the investigation things need time, I will just move forward with creating the new actions.

0/9000

Can we use the HTTP POST method in a SFMC Cloud Page to send form data to an external (not the SFMC) database? Or, are there issues?

0/9000