I want to integrate the Chat Bot application to ServiceNow by using the REST API

SreenadhChenna
Tera Contributor

Hi,

I want to integrate the Chat Bot application to ServiceNow by using the REST API.

Please help me out how to do the same.

 

Thanks,

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

Hi @SreenadhChenna ,

 

Hope you are doing great.

 

 To achieve this integration:

  1. Set up the REST API: First, ensure that your Chat Bot application has a REST API available for communication with external systems. This API should provide endpoints to send and receive messages.

  2. Create an Integration in ServiceNow: In ServiceNow, navigate to "System OAuth > Application Registry" and create a new OAuth application for your Chat Bot integration. 

  3. Obtain OAuth Credentials: Once the integration is created, you'll receive OAuth credentials (Client ID and Client Secret) from ServiceNow. 

  4. Configure REST Message: In ServiceNow, go to "System Web Services > Outbound > REST Message" and create a new REST message. Specify the endpoint URL of your Chat Bot's REST API and set the appropriate HTTP method (e.g., POST for sending messages).

  5. Set Authentication and Headers: set the authentication type as OAuth 2.0 and provide the Client ID and Client Secret obtained earlier

  6. Define Payload and Variables

 

var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod('POST');
restMessage.setEndpoint('<Chat Bot API Endpoint URL>');
restMessage.setRequestHeader('Content-Type', 'application/json');
restMessage.setRequestHeader('Authorization', 'Bearer <Chat Bot OAuth Access Token>');

var payload = {
  message: 'Hello Chat Bot!',
  user: 'JohnDoe',
  // Additional payload data as per your Chat Bot API requirements
};

restMessage.setRequestBody(JSON.stringify(payload));

var response = restMessage.execute();

if (response.getStatusCode() === 200) {
  var responseBody = response.getBody();
  // Process the response from the Chat Bot API
} else {
  var errorMessage = response.getErrorMessage();
  // Handle the error case appropriately
}

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Naresh
Tera Contributor

Hi @SreenadhChenna  Install the Virtual API plugin if you want to integration with other chatbot integration as this is Paid plugin once you install you need to configure Message Auth and Static or hash token to get details of users from other chatbot and follow the chatbot comments.

https://docs.servicenow.com/bundle/utah-servicenow-platform/page/administer/virtual-agent/task/insta...