why i am getting HTTP status 401- Unauthorized??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 10:38 PM - edited 01-20-2025 10:40 PM
When I tried with Rest message test connection it is giving me 200 but when I am doing through below script it is throwing me 401? can any one help me in solving out this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 10:43 PM
Hi @Manikantahere ,
it is Primarily due to invalid credentials (an invalid username or password) or the account not having the ServiceNow permissions required by the connector.
Please refer to these threads:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 10:59 PM
which endpoint you are consuming?
what type of authentication have you configured?
Seems the token you are using from property at line 8 is not valid and hence giving 401 error means authentication issue
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 11:08 PM
Thanks for your response Ankur,
As they only have production instance client Id, client secret for posting the data through OAuth2 they denied to give id &secret for time being, instead they agreed to give us access token while testing which is having span of an hour.
When I tested passing same token in Rest Message as a header and when I click on Test it was showing 200 but throwing me 401 when I tried same with direct code.??
I am consuming post endpoint provided by 3rd party for sending the details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 11:14 PM
you will have to generate the access token and refresh token using that client id and client secret without which it's not possible.
You can test that access token for 1 hour. but what after that
This is not how integration will work in actual prod instance.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader