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 11:22 PM
Yup, I agree but this is just for testing in sandbox once after they agreed to give client Id and secret we will generate access token and pass same while posting the details back to resource endpoint. (I hope refresh token is not needed as it is grant_type:client_credentials, correct me if I am wrong).
and my point here is what went wrong with the script when it was successful with rest message test connection by using same access token.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 11:24 PM
ideally we have faced this issue. so we should always generate fresh access token and refresh token for each API call or else what you will have to do is when the refresh token is about to expire you will have to create schedule job and get the new refresh token again
check the links I shared above.
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:33 PM
Thank you for marking my response as helpful.
If my response helped please close the thread by marking appropriate response as correct 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:40 PM - edited 01-20-2025 11:40 PM
I didn't get any link in your replies.
What is the need of refresh token when third party can't provide it using grant type as client credentials??
you said you faced this issue meaning it was successful using rest message configuration but not with direct script ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 12:17 AM
sorry sharing here
refer below links
OAuth2.0: Get new Access Token from existing Refresh Token
How to Setup OAuth2 authentication for outbound RESTMessageV2 integrations
OAuth : Script to Automate Token Request
How to generate the access token once it is expired from Business Rule?
How to get Auth Token using script when grant type is Authorization code
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