//AUTHENTICATION private static string Authenticate(UiPathOrchestratorConnection connection) { var client = new RestClient(connection.URL + "api/Account/Authenticate"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n\t\"tenancyName\": \"" + connection.Tenant + "\",\n\t\"usernameOrEmailAddress\": \"" + connection.UserName + "\",\n\t\"password\": \"" + connection.Password + "\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(ParseJson(response, "result")); }
/// <summary>Creates new user in orchestrator. Returns information about new created user</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="parameters">Name(optional), Surname(optinal), Username(required). Optional can be empty string "" </param> /// <param name="roles">Roles that will be assigned to user</param> public static bool CreateUser(UiPathOrchestratorConnection connection, string[] parameters, string[] roles) { string rolesToJson = ""; foreach (string role in roles) { rolesToJson = rolesToJson + "\"" + role + "\","; } rolesToJson = rolesToJson.TrimEnd(Convert.ToChar(",")); IRestResponse response = OrchAPI.POSTrequest(connection, "Users", "{\"Name\":\"" + parameters[0] + "\",\"Surname\":\"" + parameters[1] + "\",\"UserName\":\"" + parameters[2] + "\",\"TenancyName\":\"" + connection.Tenant + "\",\"RolesList\":[" + rolesToJson + "]}"); return(OrchAPI.GetStatus(response)); }
internal static IRestResponse DELETErequest(UiPathOrchestratorConnection connection, string urlPart, string ID) { string token = Authenticate(connection); var client = new RestClient(connection.URL + "odata/" + urlPart + "(" + ID + ")"); client.Timeout = -1; var request = new RestRequest(Method.DELETE); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Authorization", "Bearer " + token); IRestResponse response = client.Execute(request); return(response); }
/// <summary>Starts job with input parameters</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="JobInfo">Package release key, Robot ID</param> /// <param name="inputParameters">Input parameters in format {input key}-{value}. Input key is case sensitive</param> public static string StartJob(UiPathOrchestratorConnection connection, string[] jobInfo, string[] inputParameters) { string parameters = ""; foreach (string par in inputParameters) { string[] splitter = par.Split('-'); parameters = parameters + "\\\"" + splitter[0] + "\\\":\\\"" + splitter[1] + "\\\","; } parameters = parameters.TrimEnd(','); IRestResponse response = OrchAPI.POSTrequest(connection, "Jobs/UiPath.Server.Configuration.OData.StartJobs", "{\"startInfo\":{\"ReleaseKey\":\"" + jobInfo[0] + "\",\"RobotIds\":[" + jobInfo[1] + "],\"JobsCount\":0,\"Strategy\":\"Specific\",\"InputArguments\":\"{" + parameters + "}\"}}"); return(OrchAPI.ParseJson(response, "value")); }
internal static IRestResponse POSTrequest(UiPathOrchestratorConnection connection, string urlPart, string parameter) { string token = Authenticate(connection); var client = new RestClient(connection.URL + "odata/" + urlPart); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Authorization", "Bearer " + token); request.AddParameter("application / json", parameter, ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(response); }
/// <summary>Returns status of the robot</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="robotName">Name of the robot</param> public static string GetRobotStatus(UiPathOrchestratorConnection connection, string robotName) { IRestResponse response = OrchAPI.GETrequest(connection, "Sessions?$expand=Robot"); JObject jsonObj = JObject.Parse(response.Content); JArray jsonArr = JArray.Parse(jsonObj.SelectToken("value").ToString()); foreach (var item in jsonArr) { if (item.SelectToken("Robot").SelectToken("Name").ToString().ToLower() == robotName.ToLower()) { return(item.SelectToken("State").ToString()); } } return("Robot not found"); }
/// <summary>Deletes queue in orchestrator. Returns bool if delete was successful</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="ID">ID of the queue</param> public static bool DeleteQueue(UiPathOrchestratorConnection connection, string ID) { IRestResponse response = OrchAPI.DELETErequest(connection, "QueueDefinitions", ID); return(OrchAPI.GetStatus(response)); }
/// <summary>Creates new queue in orchestrator. Returns bool if created successfuly</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="parameters">Name, Description, Number of retries, Automatic retry("true"/"false"), Unique reference("true"/"false")</param> public static bool CreateQueue(UiPathOrchestratorConnection connection, string[] parameters) { IRestResponse response = OrchAPI.POSTrequest(connection, "QueueDefinitions", "{\r\n \"Name\": \"" + parameters[0] + "\",\r\n \"Description\": \"" + parameters[1] + "\",\r\n \"MaxNumberOfRetries\": " + parameters[2] + ",\r\n \"AcceptAutomaticallyRetry\": " + parameters[3] + ",\r\n \"EnforceUniqueReference\": " + parameters[4] + "\r\n}"); return(OrchAPI.GetStatus(response)); }
/// <summary>Returns information about all QUeues in the orchestrator</summary> /// <param name="connection">UiPath orchestrator connection info</param> public static string GetQueues(UiPathOrchestratorConnection connection) { IRestResponse response = OrchAPI.GETrequest(connection, "QueueDefinitions"); return(OrchAPI.ParseJson(response, "value")); }
/// <summary>Returns information about all roles in the orchestrator</summary> /// <param name="connection">UiPath orchestrator connection info</param> public static string GetRoles(UiPathOrchestratorConnection connection) { IRestResponse response = OrchAPI.GETrequest(connection, "Roles?$expand=Permissions"); return(OrchAPI.ParseJson(response, "value")); }
/// <summary>Activates or deactivates user in orchestrator. Returns bool if it was successful</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="ID">ID of the user</param> /// <param name="activate">True/False as string</param> public static bool deActivateUser(UiPathOrchestratorConnection connection, string ID, string activate) { IRestResponse response = OrchAPI.POSTrequest(connection, "Users(" + ID + ")/UiPath.Server.Configuration.OData.SetActive", "{\"active\":" + activate + "}"); return(OrchAPI.GetStatus(response)); }
/// <summary>Stops or kills job. Returns bool if it was successful</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="ID">ID of the process</param> /// <param name="strategy">Input "Softstop" to stop process, "Kill" to kill it</param> public static bool CancelJob(UiPathOrchestratorConnection connection, string ID, string strategy) { IRestResponse response = OrchAPI.POSTrequest(connection, "Jobs(" + ID + ")/UiPath.Server.Configuration.OData.StopJob", "{\"strategy\": \"" + strategy + "\"}"); return(OrchAPI.GetStatus(response)); }
/// <summary>Returns information about status of the job</summary> /// <param name="connection">UiPath orchestrator connection info</param> /// <param name="ID">ID of the job</param> public static string GetJobStatus(UiPathOrchestratorConnection connection, string ID) { IRestResponse response = OrchAPI.GETrequest(connection, "Jobs(" + ID + ")"); return(OrchAPI.ParseJson(response, "State")); }