OAuth token lasts for 30 minutes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2024 07:12 AM
We need to manually click on "Get Oauth token" in related links after every 30 mins as it last for that much time only. Is there a way so that, this process can be automated, if YES, please help by guiding step by step. Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2024 11:26 AM
I am not much sure but you will need to do manual intervention to get OAuth token. Would recommend you to use Client Credentials. I have done with client credentials. You can change the grant type and use the following code to get the access_token seamlessly-
var client_id = 'Enter your client id';
var client_secret = 'Enter your client secret';
var grant_type = 'client_credentials';
var token_endpoint = 'Enter your endpoint';
var token_grant_url = token_endpoint + "?grant_type=" + grant_type + "&client_id=" + client_id + "&client_secret=" + client_secret;
var token_request = new sn_ws.RESTMessageV2();
token_request.setEndpoint(token_grant_url);
token_request.setHttpMethod("post");
var token_response = token_request.execute();
var response_body = token_response.getBody();
var response_obj = JSON.parse(response_body);
var access_token = response_obj.access_token;
gs.info('Token request response: ' + response_body);
gs.info('Access token: ' + access_token);
Please mark my answer helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2024 09:42 AM
Hi @Amit Pandey how can I pass the token with request payload? Your help is highly appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2024 08:20 PM