How to get bearer token

Dear UiPathers

I am currently working on establishing a connection to an API. We are using Swagger UI to help us a bit. We are testing the connection in Postman and it works fine, however, when trying to replicate it in UiPath Studio we are experiencing errors like the following below:
"
{
“message”: “{"message":"loginModel must not be null","errorCode":0,"traceId":"00-3478f0c125fb77f7ce56121ad97fccb5-03d5f67e396728ef-00","resourceIds":null}”,
“level”: “Trace”,
“logType”: “User”,
“timeStamp”: “13:41:29”,
“jobId”: “4f2c16b0-4859-4e64-9f86-32e05cb3e1d2”,
“robotName”: “stud kbb-attended”,
“machineId”: 162,
“processVersion”: “1.0.0”,
“organizationUnitId”: 99
}
"

We are trying to get a bearer token that is needed to authenticate us for further work.

I am currently looking for the exact CURL command I am supossed to write in HTTP Request activity (when I click import).

I tried doing the following CURL command but it throws the above error:
"
curl -X POST “https://XXX/api/account/authenticate” ^
-H “Content-Type: application/json” ^
-H “Accept: application/json” ^
-d “{ "TenancyName": "XXX", "UsernameOrEmailAddress": "XXX", "Password": "XXX" }”
"
I have linked a screenshot of my Postman, and hopefully it can help you to tell me what to do:

Have a wonderful Friday and awonderful weekend.

Yours sincerely…
Nemanja. V

What API do you reffer to?
Orchestrator API?

Cheers

Hi @nmjvk
If you are trying to perform an API request to the Orchestrator tenant the robot is connected to, the easiest way is to use Orchestrator HTTP Request activity

If your postman example works, it can also be reproduced using HTTP request activity.

Hope it helps

@nmjvk

Take a look on below video

happy automation!!

For getting bearer token - Check below

Hi @nmjvk,

Could you please try below instead for -d (escape the double quotes):

-d “{”“tenancyName”“:”“TENANT_NAME”“,”“usernameOrEmailAddress”“:”“USERNAME”“,”“password”“:”“PASSWORD”“}”

if this still doesn’t work, i would suggest to first try to achieve the same by passing Json body instead of Curl command for the time being and see if that works for you. refer below:

And if your project is on C# language, you can refer below KB from UiPath:

https://uipath.my.salesforce-sites.com/CaseView/articles/Knowledge/How-To-Make-Orchestrator-API-Requests-Using-HTTP-Request-Activities-or-Orchestrator-HTTP-Request?lang=en_US

Hope this helps.

Regards
Sonali

Check out this video, process is explained here in detail:

Hello. Sorry for late reply, the company (and country where I am from) just had a big holiday. Yes, it is the Orchestrator API.

Cheers

Dear Sonali

I just trie to eplace my string with yours. I copied exactly this
-d “{”“tenancyName”“:”“TENANT_NAME”“,”“usernameOrEmailAddress”“:”“USERNAME”“,”“password”“:”“PASSWORD”“}”

however, I get the error

{"type":"ht tps://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":

We need to use the HTTP request activity for this project. We tried the Orchestrator HTTP Request. We need to be able to feed it a curl command and I am pretty sure you cant do it in the Orchestrator HTTP Request?

Dear yedukon

I just saw your video, but there is nothing about how to convert from Postman to UiPath Studio.

Happy Wednesday!

I didn’t your point
instead of using postman in UiPath we called http request activity it will act like as postman.
here you need to pass all parameters how you are passing URL and body and parameters same like you need construct in http activity.

from http activity you will get response nothing but output

I am sorry, but isn’t that excatly what I have done in my CURL command as shown below:

curl -X POST “https://XXX/api/account/authenticate” ^
-H “Content-Type: application/json” ^
-H “Accept: application/json” ^
-d “{ “TenancyName”: “XXX”, “UsernameOrEmailAddress”: “XXX”, “Password”: “XXX” }”

The absolute best would be if you could give me the CURL command or point out where in my CURL command I did an error, else, you have to tell me which parameters from Postman I need to fill out in my UiPath Studio HTTP Request activity. I already attached all the necessary sceenshots

Pls note that when you use Import command of “HTTP Request” activity to import a CURL command it DOES NOT import the Body argument (at least in my case it did not).

Given the error you posted it looks the body is empty.

Cheers

follow these steps exactly, you can achieve what you are trying to do.


I just tried pasting the CURL command in again and check the HTTP Request Wizard. This is what I am seeing. When I do a “Preview” I get the following error code:

{
“message”: “loginModel must not be null”,
“errorCode”: 0,
“traceId”: “00-91c14eda93e73be7b119b8ea7d390609-67d4eb8ac5618b58-00”,
“resourceIds”: null
}

So you might be right in this one. I am still trying to do some digging.

Cheers

Sure. I got same error response to “Preview”. Simply Okay it and add propper body string - same you see in Postman.

Cheers

I can hereby confirm that this was all that was needed.

So to summarise. When doing the CURL command the BODY content is not being included “for some weird reason” so you’ll have to manually add it, it my case I needed to manually include the password, username and email as a string.

Thank you for helping @J0ska have a wonderful day forward!

Cheers

1 Like

Glad to hear.

Still believe it would be better to use “Orchestrator HTTP Request” activity as proposed by @dokumentor and do not bother with authentication, just provide specific API endpoint, e.g. “/odata/Users” to get all users.

Using “HTTP Request” you will still need to build the Body (if needed by particular API call) and additionally you need to take care of the authentication, folders etc.

The only scenario when I can imagine the need of using “HTTP Request” is when you want access Orchestrator under other account than current robot.

Cheers