How to Make HTTP Callout (POST) from Salesforce Flow to OpenAI API

The Summer ’23 Release of Salesforce brings an exciting feature – you can now use the HTTP Callout POST method to send data from Salesforce to external applications, right from your Flows and without any coding. Before this, you could only use the GET method to fetch data from outside into Salesforce.

This enhancement extends the simplicity of “No Code” development with the power of APIs, letting Salesforce admins and consultants work with APIs and connect Salesforce to external applications by themselves. Gone are the days when only developers / integration architects could handle such tasks.

In this blog post, we’re set to take a deep dive, step-by-step, into integrating Salesforce with external applications using the latest HTTP Callout (POST) feature. And to illustrate this process, what will be better than integrating Salesforce with the OpenAI API (of ChatGPT fame), that’s currently setting the tech world abuzz. Get ready to blend the forces of Salesforce and AI like never before!

To show how useful the HTTP Callout POST method with OpenAI API can be, we’ll use a practical example. Imagine a customer logs a case, and you want to know how they’re feeling – are they happy, upset, or angry? Detecting customer sentiment can help you identify and prioritize which cases need to be handled urgently and which ones can wait, which can improve overall efficiency and customer satisfaction.

Consider this your launchpad. Once you’ve grasped the fundamentals, the potential applications are only limited by your creativity and vision. Picture these powerful technologies (Salesforce Flows, HTTP Callout, AI) working in unison to deliver unprecedented results for your business.

In this power-packed step-by-step guide, you will learn:

  1. How to configure External Credentials with Named Credentials & Permission Sets in Salesforce.
  2. How to make HTTP Callout using POST Method from Salesforce Flows.
  3. How to make API call to OpenAI, send the request and process the response.
  4. How to detect customer’s sentiment from the case subject and description and update the sentiment on the case record.

Now, let’s transform words into action and explore something truly groundbreaking. Enjoy your journey to the frontier of Salesforce and OpenAI integration!

NOTE: Certain sections of the guide will appear as locked in the free preview. You can download the unlocked version of the guide in PDF format by subscribing to our “All Access” Pass through the link below.

Not an “All Access” Pass Member Yet?

Get Download Access to this & 150+ More Step-by-Step Guides with “All Access” Pass. A simple and single plan to access our entire library of courses, guides, workshops & masterclasses on Salesforce.

Introducing Mastering Salesforce Flows Training Course

Liked this post? We are now offering a complete self-paced, video-based training course on Mastering Salesforce Flows. The course comes with downloadable step-by-step PDF guides, unlimited access, free upgrades, community discussion area, free preview and more. For more details, please click here.

Need Help with Flows?

Need advice on Flows? I also offer advisory & consulting services on Salesforce Flows. So, whether you want to create new Flows or migrate existing automations (Workflow Rules, Process Builder, Triggers) to Flows, I can help you analyze, design, plan & review. To initiate a discussion, please submit the contact form here stating your requirement or schedule a discussion at this URL.

References & Useful URLs

14 thoughts on “How to Make HTTP Callout (POST) from Salesforce Flow to OpenAI API”

  1. For creating the Flow resources (like on slide 49), how would you handle an Array data type? Although the /completions API does not require an Array, it is being deprecated on January 4, 2024. The recommended replacement of /chat/completions API requires messages as an array.

    1. Hi Kim,

      Once you provide the response body sample when creating HTTP Callout in Flow, Salesforce will automatically create “Apex Defined” data type. If the response body sample includes the JSON array, the Apex defined data type will also be created to store the response in Array.

  2. trying to connect to the AzureChat. took the ‘Example request’ :
    {“messages”:[{“role”: “system”, “content”: “You are a helpful assistant.”},{“role”: “user”, “content”: “Does Azure OpenAI support customer managed keys?”},{“role”: “assistant”, “content”: “Yes, customer managed keys are supported by Azure OpenAI.”},{“role”: “user”, “content”: “Do other Azure Cognitive Services support this too?”}]}
    took it from (https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions)

    it seems to build an array which has ‘messages’ on the top. i made a loop that goes over the array and puts a value in the ‘role’ & ‘content’ fields. but i get an error “Missing required input parameter: body Required field is missing…”. is this the right way to go ? maybe i should set somehow the array length ?

    THANKS

    1. Hi Amit,

      I am not familiar with AzureChat so won’t be able help much here. But did you try executing the request through “curl” command given in the URL link that you have pasted?

  3. This is incredibly helpful, thank you so much for putting this together; I had been encountering a number of issues trying to get this to work because of the lack of information on this beta feature, and this helped me cross the finish line.

    I have two questions as well: When you were working on this, and you finished the steps in creating your action, and returned to the screen on slide 73, did you find that if you clicked out of the screen at all during that time, that you would lose the action name and screen? In my case, I went to click into another browser window, and the action window I was working in just completely cleared, and I didn’t see a way to retrieve the HTTP Callout Action I had been working on from any menus.

    Second question: because of the first issue I mentioned above, when recreating the Actions and Callout settings, I was not allowed to use the same name, because it was not unique because of the dynamic apex classes the flow created. Is there a way to delete those dynamic apex classes?

    Thank you again!

    1. Hi James,

      Once you finish configuring HTTP POST, Salesforce will create an external service behind the scenes. You can then use that external service by selecting the “Action” element in the flow and typing “external” to get a list of all the external services defined in the org. (You may need to refresh your flow builder page if you don’t see the external service that you just defined)

      External Service in Flow

      To delete the dynamic apex classes, you will need to delete the corresponding external service.

      Delete External Service

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
Introducing All Access Pass