Orchestrator API Authentication using RestSharp

Hello everyone.

I am trying to Authenticate in Orchestrator via c# app with RestSharp library.
In postman everything works just fine and I am retrieving the auth. token.
But in my app I got empty response with response code 0.
I used the code snipped generated by Postman so the parameters should be the same.

When I tried another POST call to different API, everything worked fine, problem is only with the Orchestrator.
This is part of my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new RestClient("https://orchestratorURL/api/account/authenticate");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Postman-Token", "xx");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("undefined", "{\n    \"tenancyName\": \"xx\",\n    \"usernameOrEmailAddress\": \"xx\",\n    \"password\": \"xx\"\n}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            Console.ReadLine();

        }
    }
}

Any ideas what am I doing wrong? I am very new to c# and quite new to APIs in general.
Thanks)

Hey @esterba
Just problem is with your parameter Name - it should be loginModel.
Below code will work for you. :slight_smile:

try
{

            var client = new RestClient("https://orchestratorURL/api/account/authenticate");
            var request = new RestRequest(Method.POST);
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/json");
            request.AddParameter("loginModel", "{\n \"tenancyName\": \"xx\",\n \"usernameOrEmailAddress\": \"xx\",\n \"password\": \"xx\" \n}",ParameterType.RequestBody);

            
                IRestResponse response = client.Execute(request);

            Console.WriteLine(response.Content);


            if ((int)response.StatusCode == 200)
            {


            }
            else
            {

            }
            }
            catch (Exception e)
            {
                throw e;
            }  

Regards…!!
Aksh

2 Likes

@aksh1yadav

Thanks Aksh, I tried your code and I still don´t see the response (token) in my console.
Did you manage to see it when you provide your Orchestrator details?

Thanks.

Hey @esterba

Yes.
just replace your orchestrator url and Credentials with valid ones.

I used https://platform.uipath.com/api/account/authenticate

you can see token in result

Regards…!!
Aksh

1 Like

Hey,

It works fine on the https://platform.uipath.com, but it doesn´t on our instalation. Probably will be some problem with the infrastructure (firewalls etc).
Anyway thanks a lot for your help, you saved the day)

Have a good one, Ed.

2 Likes

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