The ServiceNow API lets developers access and manipulate records, manage workflows, and integrate with other services on its IT service management platform. These capabilities support automating tasks, syncing data across platforms, and boosting 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}`,
},
})
},
})
Before using the ServiceNow REST API from a workflow, configure two OAuth apps in your ServiceNow instance. These apps will grant access tokens to your users and authenticate requests to its REST API.
First, sign into your ServiceNow Developer Portal account to create or access an instance.
Go to System OAuth > Application Registry.
Create a new app by selecting New in the top right corner.
Choose Create an OAuth API endpoint for external clients:
Name your app, such as Pipedream
. Use the default settings but specify the Redirect URL: https://api.pipedream.com/connect/oauth/oa_g2oiqA/callback
.
Click Create. It will appear in the Application Registry once created.
Copy the client ID and secret from the Pipedream
app you created above.
Name this app Pipedream OAuth Validator
and add the previously copied client ID and secret.
Set the grant type to Authorization Code and the Token URL to oauth_token.do
.
Use the same Redirect URL as before.
Visit Pipedream's account page, and click Click Here to Connect An App. Search for ServiceNow and select it. Enter the client ID, client secret, and your instance name (e.g., dev98042
from https://dev98042.service-now.com/
).
Press Connect. A new window will prompt you to login to your ServiceNow instance, authorizing Pipedream's access to the ServiceNow REST API.
This ServiceNow doc outlines the flow you should implement.
The standard instructions may not apply perfectly to customized or hardened ServiceNow instances. If you face a 504 Gateway Time-out error or similar, consider these tips:
oauth_credential
table and other necessary tables.If you encounter a 504 Gateway Time-out error, refer to the 'Additional Guidance For Hardened or Mature Instances' section for solutions.
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}}