Problem with REST API building

Hi all,

Finally, I was able to get authentication from Orchestrator API call. The problem is that I had to use external REST API client, I would like to achieve the same with UiPath but I’m facing a few problems.

So my goal is to build dynamic API call based on user input but I don’t get the structure of call in HTTP Request activity.
My code returns following body structure:

@"{"“grant_type”": ““refresh_token””,
““client_id””: ““8DEv1AMNXczW3y4U15LLsdsd3jYf62jK93n5"”,
““refresh_token””: ““zF8YKb8IsDb9fjC8pGadfgeAQ-xvTh3zcVJpJHx-WIO1dQXJDr””}”

The working code is:

{
“grant_type”: “refresh_token”,
“client_id”: “8DEv1AMNXczW3y4U15LLsdsd3jYf62jK93n5”,
“refresh_token”: “zF8YKb8IsDb9fjC8pGadfgeAQ-xvTh3zcVJpJHx-WIO1dQXJDr”
}

The difference between them is a number of quotes marks on each line when I’m doing +chr(34) then I’m getting “” instead of " how to fix it? also “”" will post somehow “” …

2nd question is about the header section:
How it should look like:

How it looks like in Studio:

Is this same? or how should I prepare headers the other way?

Hi @Mikolaj_Zielinski

Try something like this:

"{""key"":""value""}"

I will try :slight_smile:
But body of this activity is a string so will it work in dictionary?

Actually, there are several ways to produce a string JSON in that Body property of the HTTP Request activity.

My current go-to methods are these two below:

  1. either have a template text file for longer JSON input bodies, that I format using String.Format method
  2. or even simpler, make a JSON from scratch, like so:
  • first import this one in the Imports panel:
    image )

    Then use something like that:

    New JObject( _
    	New JProperty("key","value") _
    ).ToString
    

It outputs this in Studio:
image

And you can either use it right away in the Body property of the HTTP Request activity, or create a JObject variable first to store and change it.

Och, one more thing:
image
Don’t use any extra single quotes, just this is enough

Content-Type: "application/json"

Thanks for so complex description, my idea is to build library to work on tasks with API so user can avoid going into orchestrator :slight_smile:

1 Like

In that case, you might want to have a look at this feature:

2 Likes

Haha thanks to you I have smth to read in train :slight_smile:

1 Like

Mikolaj, take a look at this topic:

Here is a workflow for building Json String based on dictionaries.
I use it to build a body for Jira API.

As Maciej mention check out his guide on how to start creating APIs for Orchestrator based on the Swagger documentation.
I started my adventure with API at the beginning of this year from the same topic.
:slight_smile:

@loginerror
@Adrian_Star
Do you have any clue why I can receive 404 code?


here is my endpoint:

https://cloud.uipath.com/mikolvzsadnu/MikolajDefault/orchestrator_/api/Account/Authenticate

and my body looks like this:

LoginModel { Password=“Pasword”, TenancyName=“MikolajDefault”, UsernameOrEmailAddress="mikzielinski@gmail.com" }

I’m getting:

Authenticate: The HTTP status code of the response was not expected (404).
Status: 404
Response:

For example this way is working:

Are you working on a cloud orchestrator, so, first of all, you should do tests your queries in Swagger and then pass them to flow in UiPath:

https://cloud.uipath.com/mikolvzsadnu/MikolajDefault/orchestrator_/swagger/index.html

Calling API via Cloud takes a different form than this on-premise:

Consuming Cloud API in Orchestrator:

POST https://[Orchestrator_URL]/api/account/authenticate
This call is for the on-premises Orchestrator API. Basic authentication for API is not supported for Automation Cloud Orchestrator tenants .

via:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.