The ServiceNow API enables developers to tap into the robust capabilities of ServiceNow's IT service management platform. With the API, you can create, read, update, and delete records, manage workflows, and integrate with other services. By leveraging these capabilities, you can automate routine tasks, sync data across multiple platforms, and enhance operational efficiencies.
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
servicenow: {
type: "app",
app: "servicenow",
}
},
async run({steps, $}) {
return await axios($, {
url: `https://${this.servicenow.$auth.instance_name}.service-now.com/api/now/table/incident`,
headers: {
Authorization: `Bearer ${this.servicenow.$auth.oauth_access_token}`,
},
})
},
})
Incident Management Automation: Automatically create incidents in ServiceNow when critical alerts are triggered in monitoring tools like Datadog or New Relic. This ensures timely attention to potential issues and streamlines the incident response process.
HR Onboarding Workflow: When a new employee is added to an HR system like Workday, trigger a workflow in Pipedream that creates a new user account in ServiceNow, assigns the necessary roles, and initiates onboarding tasks. This can significantly cut the time needed to get a new team member up and running.
Customer Support Ticket Sync: Synchronize customer support tickets between ServiceNow and a CRM platform like Salesforce. When a ticket is updated in ServiceNow, automatically reflect those changes in Salesforce to keep all teams aligned and informed about customer issues, ensuring a unified approach to customer service.
Before you can use the ServiceNow REST API from a workflow, you need to configure an OAuth app in your ServiceNow instance that will grant access tokens to your users and authenticate requests to its REST API.
https://api.pipedream.com/connect/oauth/oa_g2oiqA/callback
. Your app should look something like this:oauth_token.do
(without any hostname, this refers to the current instance). Finally, add the same Redirect URL as you did above: https://api.pipedream.com/connect/oauth/oa_g2oiqA/callback
. This app's configuration should look something like this when complete:dev98042
in https://dev98042.service-now.com/
.Collectively, the two apps you configured in your ServiceNow instance allow your instance to issue new OAuth access tokens for the user who authenticated in Step 6. This allows Pipedream to retrieve a fresh access token before it makes requests to the ServiceNow REST API.
This ServiceNow doc describes the general flow we ask you to implement above. In that doc, the app you create in Step 2 is referred to as the client application, and the app in Step 4 is referred to as the OAuth provider application registry record.
The instructions above are likely to work on a fresh, out-of-the-box instance but may work imperfectly on ServiceNow instances that have been customized or have applied various security hardening recommendations such as the explicit roles plugin.
Symptoms of problems here may include getting a 504 Gateway Time-out error when completing step 6 above. If you manually test the connection deatails in a tool like Postman, you may get an error like this:
{
"error_description":"access_denied",
"error":"server_error"
}
In these instances, the following tips may be helpful:
Finally, while not required, you should also check that the role has associated ACLs for any tables you want to work with; by default they may if you use snc_internal, but some fields extended from task or other tables may require additional ACLs based on your instance's configuration.
If you're getting a 504 Gateway Time-out error when attempting to connect your ServiceNow account, review the section above on "Additional Guidance For Hardened or Mature Instances".
ServiceNow uses OAuth authentication. When you connect your ServiceNow account, Pipedream will open a popup window where you can sign into ServiceNow and grant Pipedream permission to connect to your account. Pipedream securely stores and automatically refreshes the OAuth tokens so you can easily authenticate any ServiceNow API.
Pipedream requests the following authorization scopes when you connect your account:
GET
https://{{custom_fields.instance_name}}.service-now.com/oauth_auth.do
?
client_id={{custom_fields.client_id}}
&
redirect_uri={{oauth.redirect_uri}}
&
state={{oauth.state}}
&
response_type=code
POST
https://{{custom_fields.instance_name}}.service-now.com/oauth_token.do
content-type: application/x-www-form-urlencoded
accept: application/json
client_id={{custom_fields.client_id}}
&
client_secret={{custom_fields.client_secret}}
&
redirect_uri={{oauth.redirect_uri}}
&
grant_type=authorization_code
&
code={{oauth.code}}
POST
https://{{custom_fields.instance_name}}.service-now.com/oauth_token.do
content-type: application/x-www-form-urlencoded
accept: application/json
client_id={{custom_fields.client_id}}
&
client_secret={{custom_fields.client_secret}}
&
grant_type=refresh_token
&
refresh_token={{oauth.refresh_token}}