Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Access token Generation

meghna_alias
New Contributor
New Contributor

We have the requirement to call 2 api's to get the token in connection json.

First call returns access_token which is passed to second call , which also return an access-token .

The response of second call is used for API Authorization.

Please share a sample json where 2 API calls can  be used.

13 REPLIES 13

PremMahadikar
Valued Contributor
Valued Contributor

Hi @meghna_alias ,

Please refer this article: Multiple Rest API calls in Rest ConnectionJson - Saviynt Forums - 68403

Solution by  rohitkumarraj. It's a working JSON as per the article.

{
"authentications": {
"acctAuth": {
"authType": "oauth2",
"url": "SECOND URL",
"httpMethod": "POST",
"httpParams": "{\"grant_type\":\"xxxx\",\"assertion\":\"${refresh_token}\"}",
"httpHeaders": {
"Content-Type": "application/json"
},
"httpContentType": "application/json",
"authError": [
"[ADD the error message here which you get when this url fails to get response]"
],
"retryFailureStatusCode": [
401,
500,
403,
502
],
"errorPath": "message",
"maxRefreshTryCount": 5,
"tokenResponsePath": "refreshtoken",
"refreshType": "RefreshToken",
"tokenType": "Bearer",
"accessToken": "Bearer asdsdfghjk",
"refreshToken": "<>",
"refreshTokenAuthError": [
"Access Token Can not be Blank"
],
"refreshTokenErrorPath": "message",
"refreshTokenCall": {
"refreshTokenResponsePath": "access_token",
"url": "PUT FIRST CALL URL HERE",
"httpMethod": "POST",
"httpParams": "{\"username\":\"xxxx\",\"password\":\"xxxxx\",\"grant_type\":\"password\"}",
"httpHeaders": {
"Content-Type": "application/json"
},
"httpContentType": "application/json"
}
}
}
}

 

meghna_alias
New Contributor
New Contributor

In my case the token response path for both api's are access_token

Exception in RestUtilService.refreshAccessToken : org.apache.commons.lang.UnhandledException: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: org.codehaus.groovy.grails.web.json.JSONException: Misplaced key: expected mode of KEY but was OBJECT

@PremMahadikar  This is the error I am getting in logs.

vivek9237
Regular Contributor
Regular Contributor

@meghna_alias please share more details on the response body JSON structure for both the API calls.
Also the ConnectionJson you have used. Please mask the sensitive attributes.

Regards,

Vivek Mohanty


If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

Response of Call 1 :

{
    "token_type": "Bearer",
    "expires_in": 3600,
    "access_token": "",
    "scope": "groups"
}
Response of Call 2:
{
    "access_token": "",
    "issued_token_type": "",
    "token_type": "bearer",
    "expires_in": 86399
}

vivek9237
Regular Contributor
Regular Contributor

@meghna_alias Then you have to user both tokenResponsePath and refreshTokenResponsePath as "access_token"

Regards,

Vivek Mohanty


If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

meghna_alias_0-1715888867777.png

Please see the logs obtained after changing both to access_token

You can’t have 2 calls in connection json.

make first call from connection json and second call from respective jsons


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

I even tried that , in that case job fails with below error:

Cannot invoke method containsKey() on null object

Ambiguous method overloading for method java.lang.String#. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class [B] [class [C] [class java.lang.String]

vivek9237
Regular Contributor
Regular Contributor

@meghna_alias please share the connectionjson. Make sure to mask the sensitive attributes.

Regards,

Vivek Mohanty


If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

PFA

meghna_alias
New Contributor
New Contributor

@vivek9237 @rushikeshvartak @PremMahadikar 

Any suggestions as it is critical for us to achieve this connection?

As mentioned multi calls in connection json is not supported. 


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.