Create a new ServiceNow session
masterUse New-ServiceNowSession to establish a connection. This creates a script-scoped variable $ServiceNowSession which is used by default by other module functions.
Note: ServiceNow's API does not support SSO.
Retry Logic: Requests receiving retryable HTTP errors (429, 502, 503, 504, 408, 409) are automatically retried. You can control this behavior using RetryCount, RetryWaitSeconds, and MaxRetryAfterSeconds parameters.
# Basic authentication
$params = @{
Url = 'instance.service-now.com'
Credential = $userCred
}
New-ServiceNowSession @params
# OAuth with user and client credentials (automatic token refresh)
$params = @{
Url = 'instance.service-now.com'
Credential = $userCred
ClientCredential = $clientCred
}
New-ServiceNowSession @params
# OAuth client_credentials grant (machine-to-machine)
$params = @{
Url = 'instance.service-now.com'
ClientCredential = $clientCred
}
New-ServiceNowSession @params