Send API request along with string information from Console App to orchestrator and save that information in notepad

Hi ,

I have a Console Application will send user input information and subsequently initiate a UiPath API request to invoke a process within UiPath Orchestrator.

The objective is to activate the bot upon receiving the API request, extract the accompanying information in JSON format, store it in an argument or variable, and subsequently write it to a notepad file

Any help can appreciate, Thanks in advance.

Hi @jai_kumar2

You can search the related UiPath API on UiPath Swagger

https://cloud.uipath.com/{your_organization}/{your_tenant}/orchestrator_/swagger/index.html#

Also take a look here

Thanks for the reply.

Yes I go through this but i have no idea about hoe to connect Console App and orchestrator bot to Pass Arguments/Variable.

In which programming language the console application is being build ?

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
static async Task Main()
{
string orchestratorApiEndpoint = “https://cloud.uipath.com/”;
string organizationName = “jai”;
string serviceInstanceLogicalName = “RPA”;
string orchestratorApiKey = “-*****---*****”;
string processKey = “GetRequestAPI”;
string argument = “Welcome to Family”;

    await TriggerJob(orchestratorApiEndpoint, organizationName, serviceInstanceLogicalName, orchestratorApiKey, processKey, argument);
}

static async Task TriggerJob(string orchestratorApiEndpoint, string organizationName, string serviceInstanceLogicalName, string orchestratorApiKey, string processKey, string argument)
{
    using (HttpClient client = new HttpClient())
    {
        client.BaseAddress = new Uri(orchestratorApiEndpoint);

        // Ensure the correct authorization header is added
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {orchestratorApiKey}");

        // Log the headers for verification
        Console.WriteLine("Headers:");
        foreach (var header in client.DefaultRequestHeaders)
        {
            Console.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}");
        }


        var startInfo = new
        {
            ReleaseKey = orchestratorApiKey,
            Strategy = "All",
            RobotIds = new string[] { },
            InputArguments = $"{argument}",
            RobotInfo = new
            {
                MachineName = "jai******'s workspace machine",
                HostName = "RPA",
                RobotId = "123456",
            }
        };

        var jsonContent = new StringContent(JsonSerializer.Serialize(startInfo), Encoding.UTF8, "application/json");
        Console.WriteLine("JsonContent :: " + JsonSerializer.Serialize(startInfo) + "\n\n");

        string requestUrl = new Uri(client.BaseAddress + $"{organizationName}/{serviceInstanceLogicalName}" + $"/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs?organizationUnitId").ToString();
        Console.WriteLine("Request Url ::" + requestUrl + "\n\n");


        try
        {
            HttpResponseMessage response = await client.PostAsync(requestUrl, jsonContent);

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Job triggered successfully.");
            }
            else
            {
                Console.WriteLine($"Failed to trigger job. Status code: {response.StatusCode}");
                Console.WriteLine(await response.Content.ReadAsStringAsync());
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }
}

}

Hi may I get any solution for this ?