Rest API Call - Examples (Practice Session)

Hello Everyone - Hope you guys are doing good!
I want to extend my learning in Ui Path. There are few thing i have listed out in my To Do stuff to learn. So I want you guys to help me in getting this learning. First of all - I want to learn use of API Call using Ui Path. I need some reference to start this & request you to help me in some extent mentioned below,

  • How to call API using Ui Path Studio Activities
  • Where I can get some practice session on this
  • If someone provide me some test APi & details openly available to try/practice my learning.

" Keep Learning & Help Other to Learn "

2 Likes

@Lahiru.Fernando @Leonardo_Fernandes @Palaniyappan
Any help will be most appreciated.

1 Like

@hasib08 @loginerror @reda
Any help will be most appreciated.

1 Like

@bcorrea @kommijeevan
Any help will be most appreciated.

1 Like

Hi @Ashish6541

It is actually quite simple :slight_smile:

Two things you will need:

  • UiPath.Web.Activities package
  • webhook.site to test things out

Now you can send your request to that test website and see how it looks like.

See also my example here:

3 Likes

Fine
Let’s go one by one
Here you go

As @loginerror said we can do that in our community edition and we need to install this package named UiPath.Web.Activities in studio-> Design tab-> Manage Packages-> Official tab

Cheers @Ashish6541

2 Likes

@loginerror @Palaniyappan
Thank you so much for this. This seems sufficient to start with. I will try learn this things & reach out to you if in case required.

2 Likes

@Palaniyappan - I have worked on your given video tutorial and able to use GET, where REST api end point having some parameter value which when passed it is start working. Is there any examples where i can request for POST and play with it. Thanks.

@loginerror - Hi hope you are doing good at this pandemic situation. I have downloaded the file what you have shared and ran. it was working fine. I am not sure how to use this webhook.

Help me with below queries:

  • I want to hit an api where it must me having some input parameter in the endpoint and for POST request what ever value i want to add, i can simply see it. is that possible using webhook.
  • In the body section of the any POST request, if we want to add dynamic value then how to modify the body in JSON format ? Is it the same string manipulation? For an instance if i need to create user for an application, where all the uses i will be finding in a csv or excel. After the reading the data table from input source how to pass it to the JSON body.
  • I have worked on one GET request method, where end point is “http://samples.openweathermap.org/data/2.5/weather?q="+strCity+"&appid="+strAPI"”. Here in this case I am able to get the response. This case i replaced the city and apiid. This can be done by using parameter where we have to create two parameter - 1) q 2)apiid and pass. But if the case is like this - “https://testURL.in/api/users/2”, 2 is the input data, what will be the procedure using parameter?
  • If there is a POST method, in this body can only be raw data ? or is there any other way also ?
  • For POST method - in the URL sometime we are passing “https://testURL.in/api/users/ID”. ID is the one which we want to add (POST). so in this case body is not required to pass ?
1 Like

Hi @Ashish6541

Let me try to tackle your questions.

I am not sure I understand it correctly. However, the way I take it is that you want to pass a parameter with your POST API call. This can be easily done via the HTTP Request activity properties, mainly Parameters:


(these parameters are the ones that are passed as part of the URL)

First, you will pass your JSON body in the properties of the HTTP Request activity, mainly Body field.
As to how to construct this input body JSON string, I typically use a prepared templated I load from a text file that I modify with a String.Format method. It goes like follows:

  • prepare a JSON template in a Notepad file, it should look like this (note the escaped { and } signs)

    {{
    
    "someProperty": "{0}"
    
    }}
    
  • load it in UiPath using Read Text File activity and save it to a variable, let’s say templateJSON

  • the magic happens when you use an Assign activity to construct your JSON body. Let’s have another variable called bodyJSON. You could then assign it as such:

    bodyJSON = String.Format(templateJSON,valueOfSomeProperty)
    

    What it does is take the templateJSON and replace the {0},{1},{2}, etc. values with the ones you provide in that order. In the case above, the valueOfSomeProperty will replace the {0} literally from your template.
    If you use {0} across the text file, it will actually replace all its occurrences with your variable.

    Afterwards, all you have to do is pass the bodyJSON variable in the Body property of the HTTP Request activity:
    image
    (Note that you should always change the BodyFormat property to ‘application/json’ at that point.

Well, you can change the value of the BodyFormat to whatever you want. If you set its value to text/plain. you will probably be able to pass a value via the Body property as a simple string:

"yourSimpleString"

In this case, you would simply pass a variable URL like so:

I hope it clarifies things a bit :slight_smile:

3 Likes

Hi @loginerror

First of all, i appreciate your effort to answer my queries. Almost all cleared.

Coming to Point (1),
Basically i have gone through that webhook site what you have mentioned. I want to test POST method there - so i was asking how can i do that ? I am not sure how to use that site.
Please note - I have tried using some different POST end point available over inetrnet to test POST thing, which clarifies many things & gave me bit confidence.

  • All the API that i have found over internet are open does not require any authenication, token etc. So can we have something available to test where we can use token, header, OAuth, UN, PWs etc. ? Just to clarify the concepts.

@Palaniyappan @Lahiru.Fernando - You can take a look on this mentioned query - if you may help me in bit. Thank you.

" Keep Learning & Help Others to Learn "

1 Like

Och! Then I wrote too much :smiley:

Using the site is quite simple, you just use this as your URL for the HTTP Request:

As the the API with authentication, you might want to give our Cloud Orchestrator API a go then. It requires you to generate a token based on some authentication strings provided via the Cloud Platform.

You can read more here:
https://docs.uipath.com/orchestrator/reference/authenticating

1 Like

Hey @loginerror - Thanks for the explanation. I will look into that link you shared.

1 Like

Have gone thru the discussion here, and trying to get past “Paramter” error which I am facing while accessing a Yahoo API which uses OAuth1. Even though I am passing values to parameters constructing URL EndPoint I am still getting for parameters as if no parameteres been passed to activity,

@loginerror need your inputs please.

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