The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Selva Arun
Mega Sage
Mega Sage

ChatGPT Integration with ServiceNow - Latest API Guide:

 

Overview:

Recently, I was exploring the integration of ChatGPT with ServiceNow and wanted to test out the ChatGPT integration on my Personal Developer Instance (PDI). While the articles and videos I came across contained older API information, I wanted to create a new knowledge article using the latest ChatGPT API to ensure it's beneficial for anyone looking to implement or learn about this integration.

In this article, I will walk through the process of setting up the integration, including the latest API endpoint, HTTP methods, and common troubleshooting steps.

 

Steps to Integrate ChatGPT with ServiceNow:

  1. Obtain the Latest ChatGPT API Information: To start, refer to the official documentation for the latest ChatGPT API endpoint and usage details:
  2. Create a REST Message in ServiceNow:
    • Navigate to REST Message under the Application Navigator in ServiceNow.
    • Click on New and give the message a name of your choice.
    • Set the Endpoint URL to:
    • Save the record.
    • selvarun_0-1736181279804.png

       

  1. Configure the HTTP Method:
    • Under the HTTP Method related list tab, click on New and give it a name of your choice.
    • Select POST as the HTTP method. The POST method sends data to the server and requests a response, typically used when creating or updating resources.
    • The Endpoint remains the same as above.
  2. Set Authorization Header:
    • Click on HTTP Request and insert a new row.
    • In the Name field, enter Authorization.
    • In the Value field, input the following (replacing XXXXXX with your actual API token):
  • Bearer XXXXXX
    • To get the token, create an account on the ChatGPT API platform, and follow the instructions to generate your API key.

Requirements for Creating a ChatGPT API Key:

    • You must have an OpenAI developer platform account.
    • Your account should have a credit balance of >$10 (Tier 1 Usage). If the credit balance is insufficient, your key will not work, and you'll need to create a new one.

For more details on creating the API key, refer to this guide:

  1. Set Content-Type and Body:
    • Set the Content-Type to application/json.
    • Update the body to reflect the latest API changes. Here’s the new body format (note the changes from the previous version):
  • {
  •     "model": "${model}",
  •     "temperature": ${temp},
  •     "max_tokens": ${max_token},
  •     "messages": [
  •         {
  •             "role": "user",
  •             "content": "${text}"
  •         }
  •     ]
  • }
    • Save the record.
  1. Auto-Generate Variables:
    • Click on Auto-generate variables.
    • Set the following test values:
      • max_token: 1024
      • model: gpt-4-1106-preview (this part has changed from the previous version)
      • temp: 0.5
      • text: Enter any text of your choice, for example:
        Who is your favorite person?
    • Click on Test.
    • selvarun_1-1736181366645.png

       

  2. Test the Integration:
    • If you receive an HTTP Status 200 response, the integration is successful.
    • If you get a different status code, please troubleshoot the issue.
    • selvarun_2-1736181417236.png

       

Common HTTP Status Codes and Their Meanings:

Here are some common HTTP status codes you may encounter and what they mean:

  • HTTP Status 200 (OK): The request was successful, and the response contains the requested data.
    • Fix: No action needed; the integration is working as expected.
  • HTTP Status 400 (Bad Request): The server could not understand the request due to invalid syntax.
    • Fix: Double-check the API request body and ensure all required fields are correctly populated.
  • HTTP Status 401 (Unauthorized): Authentication failed or the API key is incorrect or expired.
    • Fix: Verify the API key is correct and that it's been set properly in the Authorization header.
  • HTTP Status 404 (Not Found): The requested resource could not be found on the server.
    • Fix: Ensure the endpoint URL is correct and that the API you're calling exists.
  • HTTP Status 500 (Internal Server Error): There was a server error while processing the request.
    • Fix: Check if the API service is down, or if there’s an issue on the server side. Retry after some time.
  • HTTP Status 503 (Service Unavailable): The server is temporarily unable to handle the request, usually due to overload or maintenance.
    • Fix: Wait and retry the request after some time.

Conclusion:

Integrating ChatGPT with ServiceNow using the latest API provides powerful capabilities for automating workflows and improving user experiences. Following these steps, you should be able to successfully set up the integration on your PDI or instance.

I hope this article proves useful to anyone looking to implement ChatGPT in their ServiceNow environment. If you encounter any issues or need further clarification, feel free to reach out or leave a comment if I have missed out any information or needs correction.

 

If you believe the solution provided has adequately addressed your query, could you please **mark it as 'Helpful'** and **'Accept it as a Solution'**? This will help other community members who might have the same question find the answer more easily.

 

Thank you for your consideration.

Selva

Comments
Jeff Wentworth
ServiceNow Employee
ServiceNow Employee

https://platform.openai.com/docs/api-reference/chat did not open for me. -- Thanks

Selva Arun
Mega Sage
Mega Sage

Hi,

 

It opens for me, could you please retry?

 

SelvaArun_0-1744909759356.png

 

 

Regards,


Selva 

kakas
Giga Contributor

Thanks a lot for this detailed and up-to-date guide, Selva Arun! The walkthrough on integrating chatopenai (gptopenai.fr) using the latest API (gpt-4-1106-preview) is super helpful, especially with the clear breakdown of the request structure and error handling (400, 401, 500).

Would love to see a follow-up on extending this integration with Virtual Agent or leveraging Flow Designer for no-code automation. That could really broaden the use cases for different teams.

Appreciate your contribution to the developer community! 👏

Selva Arun
Mega Sage
Mega Sage

@kakas ,

 

Thanks for the awesome feedback! I'm thrilled you found the guide helpful, especially the API breakdown and error handling. The suggestion about Virtual Agent and Flow Designer is fantastic - I'm definitely exploring those possibilities for future integrations. Stay tuned!

 

Regards,

 

Selva

Yanping Guo1
Tera Contributor

Selva, I greatly appreciate the detailed guidance you provided. I've integrated ChatGPT with ServiceNow and created a Virtual Agent (VA) topic. Although it now has ChatGPT capabilities, it's not retrieving incidents, requests, and other data. Could you provide guidance on how to fetch data from the tables?

Version history
Last update:
‎01-06-2025 08:38 AM
Updated by:
Contributors