Introduction:
ChatGPT is the new era AI tool to solve queries in an efficient way. In this blog, we will be using chatGPT to solve queries from social media API from SAP Business hub API.
ChatGPT, powered by OpenAI's language model, is capable of generating human-like text responses. SAP Cloud Platform Integration (CPI) is a robust integration platform that connects various applications and services, enabling seamless data exchange across an enterprise. OpenAI provides chat API that works as chatGPT plugin for external connectors. We will use this chat API from OpenAI in CPI to solve queries.
Pre-requisites:
- To use openAI API, you must have an account created in openAI.
- Bearer token needs to be generated from openAI that will be used in CPI forauthorization. The process to generate token is given in the next section of this blog.
- OpenAI certificate needs to be uploaded in CPI for API to work. The process ofgenerating certificate and uploading it into CPI given in the next section of this blog.
Scenario:
The iFlow consists of two APIs: one is from API business hub and other one is openAI chat API. The aim of the iFlow is to get a query from an API(In this case, it is social media activity API from API business hub) and send the query text to the openAI chat API and get the query solved using AI.
This iFlow will provide customers with real-time, AI-driven responses to their queries, improving user experiences. Also this will Utilize AI-generated insights for decision- making through the integration of ChatGPT's analytical capabilities.
Solution:
The iFlow is divided into two parts: first we will fetch the data from business hub API and filter out the query part and; In the second part we will integrate this data with openAI chat API and get the queries solved.
In the integration flow, we will include the API key for authentication for both APIs, use message filter to extract relevant information from the response and send the data to mail via mail adapter. First we will filter query from business hub API and after filtering we will send data to openAI chat API via ProcesDirect. After that, openAI will send response and again we will filter out relevant data from the response, frame it in a beautiful format and send it to mail.
IFlow Design:

Image 1
How to generate Bearer token in OpenAI?
• Create an account in
OpenAI
• Click on profile —> go to “View API keys”

Image 2
• Click on “create new secret key” and create your API key.

Image 3
• Copy and save the generated key that will be used in CPI.

Image 5

Image 6

Image 7
• Export certificate with “.cer” extension.
• Open your CPI account. Go to monitor:

Image 8
• Go to Keystore:

Image 9
• Click on add —> Certificate:
• Browse and upload the exported certificate.

Image 10
Integrating social media query from SAP business hub API and Solving the query using OpenAI Chat API
Step 1: Create an iFlow Artifact.
• Go to Design —> Integrations —> Add —> integration Flow

Image 11
• Add Details
Give the name of flow and a short description about it.

Image 12
Step 2 : Integrating social media business hub API to get query from user and solving the query using chatGPT API.
The integration part will be divided into two parts:
- Getting query from social media API from Business hub API based on the name ofthe user.
- Solving the query using OpenAI Chat API.
Part 1:
Designing an iFlow to get query from social media business hub API based on the name of the user:

Image 13
• Go to configuration details and copy sandbox Url. These will be used in SAP CPI.

Image 14
• Go to tryout section. Hit Run.

Image 15
- You will get the response as above. The query is inside the “Text” value as highlighted in screenshot above.
- Now click on “Show API Key”. You will get an API key that will be used in CPI.

Image 16
- Go to the artifact that we created in first step.
- Connect sender to start with “HTTPS” connection.

Image 17
•
Content Modifier: Add content modifier in the iFlow. This will add APIKey in the header for authorisation and fetch “name” of the user from sender as property.

Image 18

Image 19
•
Request Reply Data v2 adapter : Add a request reply and connect it with a Receiver with Data v2 connection. This will fetch social media data from business hub API.

Image 20

Image 21

Image 22
• Go to connection and paste the sandbox URL copied from business hub API.

Image 23
• Go to processing. Click “select” in resource path.

Image 24
• Select local EDMX file and upload the downloaded EDMX file from business hub.

Image 25
• Go to step 2 and select the highlighted entity.

Image 26
• Select “ObjectID”, “SocialMediaMessageAuthor”, “Text”
• Go to step 3 and select “SocialMediaMessageAuthor” and comparison as equal.

Image 27

Image 28
• Click on finish.
• Add the headers in the data connection as shown in image 29.

Image 29
• Filter : Add filter in the path. This is to filter out the query part from the data.

Image 30
• Content Modifier: Add content modifier top set the content type.

Image 31
• Now add a receiver and connect it with end message using ProcessDirect and give a unique path name.

Image 32
Part 2:
Integrating iFlow with chatGPT API and sending the data through adapters. In this case, we will use mail adapter to send the data.
• Integration Process: Add a new Integration process in the same artifact.

Image 33
•
Sender: Add a “Sender” in the new Integration flow.

Image 34
•
Start message: Add a “Start Message” and similarly add an “End Message” in the IFlow.

Image 35
• Connect sender and start message with process direct connection and give the same path as in above iFlow ProcessDirect.

Image 36
•
Content Modifier: Add a content modifier in the flow with following inputs
- Message header to set content type as application/json as openAI API take data in json format only. Also this will authorise openAI API using Bearer token authorisation as given below.
- Exchange property to fetch the query from social media API
- Message body to frame data in standard required format as suggested in openAI documentation. Refer link for more information.

Image 37

Image 38

Image 39
•
Request Reply Http Connection: Add request reply and connect it with a receiver using http connection.
Paste the link in the address to use chat feature of openAI : “
https://api.openai.com/v1/chat/completions”

Image 40
• Json to XML converter: Add a json to xml converter.The data we get from openAI is in json format. To process it further, it should be converted into to xml format as CPI processes data in xml format only.

Image 41
• Filter: Add a filter to get the resolution fetched from openAI.

Image 42
• Content Modifier: Add a content modifier to set content type and get the resolution in beautified way.

Image 43

Image 44

Image 45
• Mail Adapter: Now add a receiver and connect it with mail adapter to send the resolved query via mail.

Image 46

Image 47

Image 48
Step 3 : Save and deploy the artifact.
Testing the iflow using postman:

Image 49

Image 50
In Conclusion:
Integrating ChatGPT with SAP Cloud Platform Integration presents a remarkable opportunity to transform user interactions and business processes. By leveraging the power of AI-driven conversations, organizations can enhance customer experiences, streamline operations, and unlock new avenues of innovation.
In this blog, we explored the steps to integrate ChatGPT with SAP CPI. As technology continues to evolve, this integration showcases the endless potential of AI and integration platforms in creating a smarter, more efficient future.
Thanks and Regards,
Ashutosh Kumar