401 Unauthorized error from Powershell to ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2020 07:31 AM
Hello Experts,
Don't know whether this is a right question asking here. But I need your assistance on this.
There is a powershell script which connects SN to customer_contact table to fetch the record via token concept. I don't know why I am getting below error. I've tried changing the token but still issue persists. Can anybody help me to sort this out.
VERBOSE: Getting customer contacts from SNOW ContactUri: https://{instance_name}.service-now.com/api/now/table/customer_contact?sysparm_query=u_portalenabled_1=yes&sysparm_fields=name,email,u_portalenabled_1,sys_id,active,user_name
VERBOSE: GET https://{instance_name}.service-now.com/api/now/table/customer_contact?sysparm_query=u_portalenabled_1=yes&sysparm_fields=name,email,u_portalenabled_1,sys_id,active,user_name with 0-byte payload
>> TerminatingError(Invoke-WebRequest): "The remote server returned an error: (401) Unauthorized."
>> TerminatingError(LogEvent): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Error retreiving data from the SNOW web service: The remote server returned an error: (401) Unauthorized."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2020 07:24 AM
I did it via postman and it works fine. Really I don't know how to debug this. Can you help me via zoom call please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2020 09:05 AM
Hi Vikram,
So definitely issue with the way API is called from powershell command.
I am not having any expertise in powershell scripts/command so may not be able to guide you.
But I believe the root cause will be found when you check the powershell script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2023 11:31 AM
This is an old thread at this point, but I was getting a similar error and the root cause was that my password contained a "$" character which, in a PowerShell script, requires the escape character preceding it: `
Alternatively, the password can be sandwiched in single quotes instead of double quotes, which may be a valid enhancement request for the ServiceNow REST API Explorer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
For my issue , i resolved with this
In my case when a create a new user to user in this powershell command my default password is so long (+- 128 caracters). I changed to a short password (16 caracteres) and the 401 problem is resolved.
importante
I put this roles to user
import_transformer
and flag the option "Internal Integration User" in user register