I am using HTTP Request activity to call a REST API which uses OAuth2 authorization. I was able to get the access token successfully and I extracted necessary value from returned JSON response by using Deserialize JSON activity. Assume extracted value is in a variable called acsTknRspns (Type: JObject).
When I provide set this value to the OAuth2Token value of my next HTTP Request, the workflow ends with code 401, unauthorized access.
But I overcame this issue as follow.
I set the Headers of the next HTTP Request like,
Bearer + acsTknRspns(“access_token”).ToString.
By this way, I can make a successful request.
Am I using the OAuth2 wrong? If so how to set access token value in OAuth2Token property?
Can you guide me regarding this one Bearer + acsTknRspns(“access_token”).ToString. where have you used this argument and why have you given the default vale as this?
As mentioned I am passing this as argument to Headers of the HTTP Request activity. Also Bearer + Access Token Value is the default way to set headers in OAuth 2.0 authentication.
You can include your access token in your POST body if the service accepts access token in body.
I can see that you were able to get the access token. I’m not able to get the access token using the http request. Could you please help me on this or share any sample xaml if available
Thank you for responding. I do not have the client ID and client secret. I was able to get the access token from postman by using grant type password and using the password and username.
Hi @nsiva, while making this first call to REST API to get access token, was the calling method GET or POST. Also, did you pass anything in header or body during this call?
REST API calls to get access token was a POST request since we need to provide details such as client id, client secret etc. Also in my case, I did not pass anything in my header.
In general, when making HTTP requests, we set headers with Content-Type ==> application/json (for a JSON body). We don’t need to specify this here since we configure that using BodyFormat property.
I am little bit confused on your question. Are you having trouble in getting your access token? If that is the case, simply you can get it by using HTTP Request Activity with relevant parameters in body with no value set for OAuth2token (since this is what we are trying to get). Then you can deserialize server response and extract the field containing access token.
In my case my server returned a JSON response.
{
“accessToken”:“ABCDxxsdsd”,
“timeStamp”:“…”,
…
}
So I used deserialize JSON activity and extracted relevant field (“accessToken”). (See above discussion)
If your are having issues in using your access token follow this.
Actually I was not able to make a successful request by setting OAuth2Token parameter. But behind the scenes, HTTP headers are set as below for a OAuth2 authentication.
“Authorization”: “Bearer + accessToken (access token you get from server)”
So what i did was (as explained in above discussion), I manually set the header authorization field as above instead of using OAuth2 token.
I am trying to get the access token by HTTP Request POST Method, after passing the required parameters in the body i am getting the response as “unsupported_grant_type”.
I can get Service now access token in postman, but not from UiPath http activity, I’m getting “access_denied” error. I have provided grant_type,username,password,client_id and client_secret everything in body and header as Content-Type: application/json.
I am getting {
“error”: “unsupported_grant_type”
} after following your instruction in this thread . Appreciate if you could share xaml file for reference calling endpoint for generating token using client id and password with grant type as password_credentails.