Ready to build your (perhaps first, but definitely not last) integration into OpenAI?1
In part one of this project, we got access to a Salesforce org with OmniStudio and obtained a API key to allow you to makes calls to OpenAI. And we discussed security concerns around keeping your key safe.
In this part two, we’ll actually see calling the “models”2 API endpoint to retrieve a list of AI models OpenAI supports – and then displaying the results in the Salesforce UI. This will set the stage for a subsequent project, as we’ll have the mechanics of the integration in the bag.
Let’s start with getting an Integration Procedure built, which is enough to see the integration is working, and then we’ll make a quick FlexCard to show it in the UI.
Did you get forwarded this post? Why not subscribe for yourself?
Build an Integration Procedure to Retrieve Models
There’s really two sub-steps to doing this: enabling your org to access OpenAI and then building an Integration Procedure to make the REST call.
Remote Site Settings
The first step is to go into the Remote Site Settings in Salesforce Setup and tell the org it’s OK to access OpenAI. Press the “New Remote Site” button, and then enter the URL (and name) for OpenAI:
Name: OpenAI
URL: https://api.openai.com
Press Save, and you’re allowed to make calls to the API.
Integration Procedure
Next we’re going to create an Integration Procedure.
From the OmniStudio Integration Procedures page, click the new button to start creating our Integration Procedure. When you do that, you’ll be asked to enter the name, type, and subtype for the new procedure:
Type: OpenAI
SubType: DirectTest
Name: anything you like, but I tend to use the type and subtype together in some form
When you’ve entered that data, press Save at the bottom to allow you to start editing your Integration Procedure.
Now, drag out an HTTP Action element. You will configure it like this:
The Element Name is getModels (to be clear, it doesn’t matter, except that the name here is used in the Response action and so the two have to match.)
The HTTP Path needs to be “https://api.openai.com/v1/models”.
The HTTP Method is “GET”
Expand the REST OPTIONS section and click “Add New Header:
Key=Authorization
Value=Bearer sk-your OpenAI key3
If you preview the Integration Procedure now, you won’t see a result, but in the Debug Log you should see the full response from Open AI. Depending upon how impatient you are you can preview or not.
Drag out a Response Action in your Integration Procedure. Configure it like this:
The Send JSON Path is getModels:data
Preview it, and you should see the list of models in the response.
Go back to the Properties and click on “Procedure Configuration” and then click on the “Activate Version” button at the bottom.
Congratulations, you have a working integration procedure!!!
Building a FlexCard
The last step in our project is to build a FlexCard to show the data in the UI. Go to the “OmniStudio FlexCards” page in Salesforce and press the New button to start building a FlexCard.
On the first screen, fill it out like this:
Name: OpenAI_Models
Title: OpenAI Models (Or just leave it as is)
Theme: Lightning
Author: your name4
Press Next.
In the next page, select the Source Type as Integration Procedure and press Next.
On the next page after that, enter the name of your newly created Integration Procedure, OpenAI_DirectTest. And press Next.
On the last page of the creation wizard, "Configure Inputs", you can just press Save. But if you like, you can press Fetch to verify that the right data is being retrieved.
That closes the wizard and brings you into the UI Editor.
Next, drag a Datatable onto the card
And you’re done!
You now have a fully functioning card that shows data live from OpenAI. You can play with the columns and formatting if you like, but it’s not terribly valuable: this isn’t a card you’ll put in front of a user.
Wrap-up
We obtained the prerequisites for hooking up Salesforce to OpenAI in part one, and learned why leaving the API key in the open has risks. Then, in part two, we built an integration procedure to call OpenAI and show the results in a FlexCard.
That wasn't too hard, I hope? But if you are stuck or something’s unclear, you can reply to this email (or find me somewhere else), I’m happy to help. Should be easy to get you up and running.
If you liked this post, why not share it with someone who might be interested?5
That was a rhetorical question. Of course you are! This is going to be great … soon!
A reminder about the Models endpoint: it’s free to call, and it’s nice to not run up a bill while you’re getting things working. It also is easy to call, as it doesn’t take any input arguments, so we don’t end up with extra complexity right off the bat.
The API Key you see in the video has already been deactivated :-)
Or just leave this as is, ahem, Mr./Ms. Self!
Although if you want to look like a genius and you don’t want to give away your secret well, then mum’s the word. I won’t tell a soul.