The CreatorCon Call for Content is officially open! Get started here.

401 Unauthorized error from Powershell to ServiceNow

Vikram3
Giga Guru

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."
13 REPLIES 13

Vikram3
Giga Guru

Can anybody assist.

Hi Vikram,

 

What authentication type you are using for REST Service (Basic or OAuth)? is the user profile used to authenticate REST call has "snc_platform_rest_api_access" role? 

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

user has admin role

Hi Vikram,

Usually error 401 means incorrect username and password

Is that user having valid Table level READ ACL to access the table data

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader