How to Connect Chat GPT to Salesforce Flow
Have you heard of this awesome new craze called AI? Apparently it’s the talk of the town and just about every stakeholder is saying they need to be using AI in their workflows. So let’s just get right to business and discuss how you can connect Salesforce Flow to Chat GPT. If you do not have an OpenAI API Key stop here and obtain one before continuing.
Step 1: Create External Credential
Navigate to Setup > Named Credential, click the tab for External Credentials and click New.
Name your credential OpenAI External Credential and set the Authentication Protocol to Custom.
Next, create a new Custom Header for your credential.
Now create a Principal. This is a must as this enables giving access to the callout by profile or permission set.
Step 2: Get GPT Model Response JSON
Open Terminal and execute the below code snippet to retrieve the chat completion JSON response for the model you are using.
You can review full API details on Open AI’s website.
Note: Every GPT Model has its own JSON response so just take note that as new models are created that you want to leverage you will need to build a new callout and hence a new sub flow so make sure to think through how you design your solution knowing that models will change.
curl https://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR API KEY" \ -d '{ "model": "gpt-4o", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'
Step 3: Create HTTP Callout Action
Create a new flow and create a new HTTP Callout.
Give the callout a name that indicates the model being used.
In the next step use the sample JSON request details below.
{ "max_tokens": 1, "temperature": 2.5, "messages": [ { "role": "sample string", "content": "sample string" }], "model": "sample string" }
In the final step for setting up the callout use the JSON response you generated via the API.
And bam - you have created a callout to Chat GPT with the only cost being API credits!
Now you have unleashed the power of Chat GPT within Salesforce flow. The only question is how will you use this power. Note: no AI was used to write this blog post. If you are struggling with this implementation or are looking to purchase our solution please reach out now - we can have you set up today! Our solution supports the newest model which is GPT-4o at the time of writing this post and is built to easily enable new models as they are released.