Share same HTTP Client for HTTP Requests

Hi,

I need to use an external API and to authenticate, we need to perform two calls. The first one allows to connect and the second one retrieves a token. Unfortunately the second call doesn’t work if it doesn’t share the same “HTTP Client” as the first call. In C#, it looks like this:

    var client = new HttpClient(new HttpClientHandler()
    {
        UseDefaultCredentials = true
    });
    var request2 = new HttpRequestMessage(HttpMethod.Post, "First Link to authenticate");
    var response2 = client.SendAsync(request2).Result;
    var request = new HttpRequestMessage(HttpMethod.Post, "Second link for the token");
    var response = client.SendAsync(request).Result;

To reproduce this behavior in UiPath, I tried to put two “HTTP Request” activities but it doesn’t work. It seems like the two calls don’t share the same HttpClient. I can use the Invoke Code activity but I would like to know if there is a way to make it work using the HTTP Request activities.

Thanks a lot for your help!

Best regards,

1 Like

Hello @melanie!

It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.

First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.

You can check out some of our resources directly, see below:

  1. Always search first. It is the best way to quickly find your answer. Check out the image icon for that.
    Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.

  2. Topic that contains most common solutions with example project files can be found here.

  3. Read our official documentation where you can find a lot of information and instructions about each of our products:

  4. Watch the videos on our official YouTube channel for more visual tutorials.

Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.

Thank you for helping us build our UiPath Community!

Cheers from your friendly
Forum_Staff

Would it work via Postman? (two consecutive calls from Postman would be the closest to trying to redo it via 2 HTTP Request activities)

I assume that maybe it should, if you can exactly replicate the second API call exactly as per the state after the first one is executed, so all headers, body, cookies, etc.