logo

NJP

(Another way to ) Integrate ServiceNow to ChatGPT: with no-code

Import · Jan 30, 2023 · article

Hi All

You have probably tried already to communicate with a new AI tool ChatGPT (advanced chatbot).

Of course, I also tried to ask ChatGPT various tricky questions and one of them was "how to integrate ServiceNow with ChatGPT? Do I need to use a code for that?". ChatGPT replied with a quite generic manual, confirming that writing a code is required and pointing to a need to use RestAPI with scripts, vaiables, etc.

But hey ChatGPT - why do I need to code anything there if ServiceNow provides a great OOB tools like Flow Designer? So, please see below a complete manual for introducing ServiceNow - ChatGPT integration (or, actually, an integration based on OpenAI GPT-3 API (ChatGPT is also related to GPT-3)) using LOW/NO code development approach.

Let me come up with a **USE CASE** first:

* If caller submits an incident and its description is empty, description text has to be generated by AI tool, and provided back to the newly created incident updating it.
* Implementation must be done in Flow Designer with no steps that require coding.
* This is a learning exercise; it should be possible to repeat all steps from this manual in PDI (Tokyo)

**Step 1.**

Create an API key by accessing OpenAI API page.

Create a new application in ServiceNow (usually I use App Engine Studio for that). I created "MyOpenAI" application, that will also be a spoke in Flow Designer.

Navigate to Connections & Credentials -> Credentials, create new API Key Credentials (with API key value from OpenAI), add this Credential to Credential Alias (create it first). In my case, resulting form for API key credential "ChatGPT" looks like:

**Step 2.**

Go to Flow Designer, create a new Flow (I named it as ChatGPT\_Ask).

Define a trigger: New incident is created and its Description is empty:

Go to Flow Actions, create a new Action (I named it as ActionOnChatGPT) that has two steps.

Few bullet points here:

* Action "ActionOnChatGPT" has one Input (I named it as "prompt") and one Output (named it as "Answer)
* Rest Step: please pay attention to Request details, Headers used and Request (body) content.
* Very important: API key is provided in the header as a reference to the credentials defined before. Key should **not be** set as a clear text!

* JSON Parser step
* For the note: The JSON parser step is not available in the base system and requires the Integration Hub Standard Pack Installer.
* How to use JSON parser - please watch a video:

* Outputs: this is where I put a little (very very very little code ) to return just a value of the "answer" text but not the full JSON object.

Return to Flow and add two actions:

* Action that you just created (in my case it is ActionOnChatGPT) where you pass a Short Description (and some text around - just to have more fun) from the incident:

* "Update Incident Record" where incident's description is updated with a text produced by ChatGPT (over Action).

Resulting flow looks like:

**Step 3.**

Test the flow and actions inside by creating a new incident with empty Description.

After submitting an incident (I did it over Platform UI using "Save" button) with empty Description, my incident was updated itself with a description text taken from AI.

Hope it helps!

View original source

https://www.servicenow.com/community/developer-articles/another-way-to-integrate-servicenow-to-chatgpt-with-no-code/ta-p/2462662