Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain an OAuth token from ServiceNow in a Bot Framework skill within Power Virtual Agent, you can follow these steps:

  1. Create an OAuth client in ServiceNow.
  2. Note down the client ID and client secret.
  3. In Power Virtual Agents, create a new skill or open an existing one.
  4. Click on the “+” sign to add a new code action from the list of actions.
  5. Write code in the code editor to make a request to the ServiceNow OAuth server to obtain a token. Below is an example code snippet:
const axios = require('axios');

const serviceNowUrl = 'https://yourinstancename.service-now.com/oauth_token.do';
const clientId = 'your_client_id';
const clientSecret = 'your_client_secret';
const scope = 'useraccount';

const data = {
    grant_type: 'client_credentials',
    client_id: clientId,
    client_secret: clientSecret,
    scope: scope
};

const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
};

axios.post(serviceNowUrl, new URLSearchParams(data), { headers })
    .then(response => {
        const token = response.data.access_token;
        console.log('OAuth token:', token);
        // use the token to make API requests to ServiceNow
    })
    .catch(error => {
        console.error('OAuth error:', error.message);
    });
  1. Save the code action and add it to your bot's dialog tree.
  2. Call the code action from your bot's dialog flow to obtain an OAuth token from ServiceNow. You can then use this token to make authenticated API requests to ServiceNow from within your bot.