With c# i want to start a process and pass arguments to it, it is possible? chat gpt say to do an external application api orchestrator with scope job and execetions, and a token, he give me code but it doesn’t work. Anyone can help me? Thanls
Hello,
Can you give some more context? Yes you can, but you need to be going through the UiPath Orchestrator, there are API’s to deal with it and you need to have purchased an unattended licence etc.
I assume you are good at C#, you have to call
API endpoint:
https://cloud.uipath.com/your_org/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs
Payload like this:
Hello @e0f13150f0c3f376ac845921e
If you are familiar in working with APIs, then you can take a look at the Orchestrator API documentation (Swagger) by accessing the URL:
https://cloud.uipath.com/{your_org_name}/DefaultTenant/orchestrator_/swagger
Regards
Soren
Can you suggest a skeleton where to put coordinates?
For example chat gpt create this sample code but it doesn’t work:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
class Program
{
// ===== DATI DA PERSONALIZZARE =====
private const string Organization = “xxxxxxxxxx”;
private const string TenantName = “DefaultTenant”;
private const int FolderId = 6413369;
private const string AppId = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
private const string AppSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private const string RefreshToken = "xxxxxxxxxxxxxxxxxxxxxxxx";
private const string ProcessName = "xxxxxxxxx";
static async Task Main()
{
try
{
string token = await GetAccessTokenAsync();
string releaseKey = await GetReleaseKeyAsync(token);
Console.WriteLine("ReleaseKey trovata: " + releaseKey);
await StartJobAsync(token, releaseKey, "VALORE_ARGOMENTO");
}
catch (Exception ex)
{
Console.WriteLine("ERRORE: " + ex.Message);
}
}
// ================= TOKEN ==================
static async Task<string> GetAccessTokenAsync()
{
using var client = new HttpClient();
var url = $"https://cloud.uipath.com/{Organization}/identity_/connect/token";
var body = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("grant_type", "refresh_token"),
new KeyValuePair<string,string>("client_id", AppId),
new KeyValuePair<string,string>("client_secret", AppSecret),
new KeyValuePair<string,string>("refresh_token", RefreshToken)
});
var response = await client.PostAsync(url, body);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine("TOKEN RESPONSE: " + content);
if (!response.IsSuccessStatusCode)
throw new Exception("Errore token");
var json = JObject.Parse(content);
return json["access_token"]!.ToString();
}
// ================= RELEASE KEY ==================
static async Task<string> GetReleaseKeyAsync(string token)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("X-UIPATH-OrganizationUnitId", FolderId.ToString());
var url = $"https://cloud.uipath.com/{Organization}/{TenantName}/orchestrator_/odata/Releases?$filter=ProcessKey eq '{ProcessName}'";
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine("RELEASE RESPONSE: " + content);
var json = JObject.Parse(content);
var releaseKey = json["value"]?[0]?["Key"]?.ToString();
if (string.IsNullOrEmpty(releaseKey))
throw new Exception("ReleaseKey non trovata!");
return releaseKey;
}
// ================= START JOB ==================
static async Task StartJobAsync(string token, string releaseKey, string parametro)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("X-UIPATH-OrganizationUnitId", FolderId.ToString());
var url = $"https://cloud.uipath.com/{Organization}/{TenantName}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs";
var payload = new
{
startInfo = new
{
ReleaseKey = releaseKey,
Strategy = "Specific",
NoOfRobots = 0,
JobsCount = 1,
InputArguments = JsonConvert.SerializeObject(new
{
ArgParametro = parametro // 🔥 questo deve combaciare col nome argomento in UiPath
})
}
};
string jsonPayload = JsonConvert.SerializeObject(payload);
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine("JOB RESPONSE:");
Console.WriteLine(result);
}
}
I’ve community edition, i’ve a robot and a process, this is a sample code written by chat gpt where you can find my actually way to solve (sorry for my english i’m italian): using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
class Program
{
// ===== DATI DA PERSONALIZZARE =====
private const string Organization = “xxxxxxxxxx”;
private const string TenantName = “DefaultTenant”;
private const int FolderId = 6413369;
private const string AppId = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
private const string AppSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private const string RefreshToken = "xxxxxxxxxxxxxxxxxxxxxxxx";
private const string ProcessName = "xxxxxxxxx";
static async Task Main()
{
try
{
string token = await GetAccessTokenAsync();
string releaseKey = await GetReleaseKeyAsync(token);
Console.WriteLine("ReleaseKey trovata: " + releaseKey);
await StartJobAsync(token, releaseKey, "VALORE_ARGOMENTO");
}
catch (Exception ex)
{
Console.WriteLine("ERRORE: " + ex.Message);
}
}
// ================= TOKEN ==================
static async Task<string> GetAccessTokenAsync()
{
using var client = new HttpClient();
var url = $"https://cloud.uipath.com/{Organization}/identity_/connect/token";
var body = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("grant_type", "refresh_token"),
new KeyValuePair<string,string>("client_id", AppId),
new KeyValuePair<string,string>("client_secret", AppSecret),
new KeyValuePair<string,string>("refresh_token", RefreshToken)
});
var response = await client.PostAsync(url, body);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine("TOKEN RESPONSE: " + content);
if (!response.IsSuccessStatusCode)
throw new Exception("Errore token");
var json = JObject.Parse(content);
return json["access_token"]!.ToString();
}
// ================= RELEASE KEY ==================
static async Task<string> GetReleaseKeyAsync(string token)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("X-UIPATH-OrganizationUnitId", FolderId.ToString());
var url = $"https://cloud.uipath.com/{Organization}/{TenantName}/orchestrator_/odata/Releases?$filter=ProcessKey eq '{ProcessName}'";
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine("RELEASE RESPONSE: " + content);
var json = JObject.Parse(content);
var releaseKey = json["value"]?[0]?["Key"]?.ToString();
if (string.IsNullOrEmpty(releaseKey))
throw new Exception("ReleaseKey non trovata!");
return releaseKey;
}
// ================= START JOB ==================
static async Task StartJobAsync(string token, string releaseKey, string parametro)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
client.DefaultRequestHeaders.Add("X-UIPATH-OrganizationUnitId", FolderId.ToString());
var url = $"https://cloud.uipath.com/{Organization}/{TenantName}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs";
var payload = new
{
startInfo = new
{
ReleaseKey = releaseKey,
Strategy = "Specific",
NoOfRobots = 0,
JobsCount = 1,
InputArguments = JsonConvert.SerializeObject(new
{
ArgParametro = parametro // 🔥 questo deve combaciare col nome argomento in UiPath
})
}
};
string jsonPayload = JsonConvert.SerializeObject(payload);
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine("JOB RESPONSE:");
Console.WriteLine(result);
}
}
Can you give me a skeleton of call?
Yeah no worries bud your English is all good so far.
The Community version is only for learning etc.
If you want to do this for an actual process, you need to purchase a licence.
When I asked for more context, I wanted to know what are your wider reasons for wanting to do it via C# etc, it might not be the best way, there is a reason its not set up for this to work straight out of the box. Can you explain your use case?
You could take a look at the post below.
