Orchestrator API Post Schedule via .ProcessScheduleDto in Studio. How to DEV in Studio?

Hi,
How can I translate the API json request from Swagger UI with sample data into logic in UiPath Studio?:

{
   "Enabled": true,
   "Name": "API_Schedule",
   "ReleaseName": "Process_name",
   "EnvironmentName": "DEV",
   "StartProcessCron": "0 0 *? * * *",
   "ExecutorRobots": [
     {
       "Name": "ROBOT_1"
     }
   ]
}

I have created the appropriate API command for starting the robot, created using:

Now I want to learn how to create a schedule.

Screen from Studio:

I have created the following commands:

processSchedule = New UiPathOrchestratorAPI.ProcessScheduleDto

UiPathOrchestratorAPI is Service in Imports

 processSchedule.Name = "API_Schedule"
 processSchedule.ReleaseName = "Process_name"
 processSchedule.Enabled = True
 processSchedule.StartProcessCron = "0 0 * ? * * *"
 processSchedule.EnvironmentName = "DEV"
 processSchedule.StartStrategy = 0

processSchedule.ExecutorRobots = *what phrase I need to enter here?*

How the phrase for the data collection should be created to match the json entry:

"ExecutorRobots": [
    {
      "MachineName": "string",
      "Name": "string",
      "Description": "string",
      "Id": 0
    }

processSchedule.ExecutorRobots needs command in:Value(ICollection<,RobotExecutorDto>)

image

What minimum data is needed to create a schedule?

In my experience, working with the API using the messy REST Activities within Studio has generally been a headache, but I think this just looks convoluted and actually is pretty simple. I would in general suggest leaving API development to Visual Studio or other things, however, potential solution below.

If you wish to continue with Studio, from what I can tell from here this value can be blank if you don’t require scheduling this on specific robots.

However, if you do need to launch from specific robots, this is just a Collection of RobotExecutorDto objects which have the same four properties that are in the JSON.

So if you created a variable RobotExecutorDto robo = new RobotExecutorDto() you could then assign the data to it: robo.MachineName = xyz, robo.Name = xyz, robo.Description = xyz, robo.Id = ##. As far as I can tell ONLY the Id is required, the rest of the fields are nullable.

Do something along these lines:

List<RobotExecutorDto> robots = new List<RobotExecutorDto>();
List<int> robotids = new List<int>(){12, 15, 2, 6};
foreach (int id in robotids) {
    RobotExecutorDto tempObject = new RobotExecutorDto();
    tempObject.Id = id;
    robots.Add(tempObject);
}

Then you can pass in the Collection of robots that it needs to be scheduled on.

1 Like

Hi @mike.vansickle
Thanks for the information that turns out to be important for figuring out the problem.

What and how I did:

Creating a variable with a specific service and type:
robotExecutorID = New UiPathOrchestratorAPI.RobotExecutorDto ()

Specifying the variable (variable.Id = robot ID number)
robotExecutorID.Id = int

Introduction of the variable to: ICollection <, RobotExecutorDto>
processSchedule.ExecutorRobots = {robotExecutorID}

However, another problem arises.
While executing the ‘Post’ command I have:

Status: 404
Response:
"message": "The job's associated process could not be found", "errorCode": 1002, "

What is the cause?

I mean you’re getting a 404 Response, so I’m lead to believe the endpoint is invalid or something of that nature. I’m not too familiar with troubleshooting API requests in Studio, I chose to do any API work in Visual Studio rather than within Studio since it tends to feel more cluttered in Studio.

I have the same API behavior when testing it in SWAGGER and in STUDIO.

I tried to enter full data in the code, as well as minimal. Here I give you a teaser on minimal data.

Depending on the parameters, for example
1st case:

{
  "Enabled": false,
  "Name": "API",
  "ReleaseKey": "***** - **** - **** - ******",
  "ReleaseName": "R052_DEV",
  "EnvironmentName": "DEV",
  "StartProcessCron": "0 0 0/1 1/1 *? *",
  "ExecutorRobots": [
    {
      "Id": 19
    }
  ]
}

SWAGGER responds:

Response Body
{
  "message": "The job's associated process could not be found",
  "errorCode": 1002,
  "resourceIds": null
}
Response Code
404

2nd case:
If I additionally add Release ID:

{
  "Enabled": false,
  "Name": "API",
  "ReleaseId": 159,
  "ReleaseKey": "***** - **** - **** - ******",
  "ReleaseName": "R052_DEV",
  "EnvironmentName": "DEV",
  "StartProcessCron": "0 0 0/1 1/1 *? *",
  "ExecutorRobots": [
    {
      "Id": 19
    }
  ]
}

SWAGGER gives such a response:

Response Body
{
  "message": "An error has occurred.",
  "errorCode": 0,
  "resourceIds": null
}
Response Code
500

3rd case:
However, if I enter the existing schedule name in the code:

{
  "Enabled": false,
  "Name": "API_Schedule",
  "ReleaseKey": "***** - **** - **** - ******",
  "ReleaseName": "R052_DEV",
  "EnvironmentName": "DEV",
  "StartProcessCron": "0 0 0/1 1/1 *? *",
  "ExecutorRobots": [
    {
      "Id": 19
    }
  ]
}

In turn, SWAGGER gives such a response:

Response Body
{
  "message": "The name API_Schedule is already used.",
  "errorCode": 1001,
  "resourceIds": null
}
Response Code
409

Instead, I worked around this problem and created a query:

POST /odata/ProcessSchedules/UiPath.Server.Configuration.OData.SetEnabled

This is a module for enabling and disabling schedule. Requirements are minimal:

  • schedule must already be created in Orchestrator,
  • POST requires two values:

.

{
  "scheduleIds": [
    0
  ],
  "enabled": true
}

and works very well.

However, the question remains how to solve the puzzle of creating a new process schedule by POST / odata / ProcessSchedules?

1 Like

Hi @Adrian_Star

I experimented a little and this seems to be the working JSON input:

{
  "Enabled":"False",
  "Name": "API",
  "ReleaseId":****,
  "ReleaseKey":"****",
  "ReleaseName": "HelloWorld_Robo_Maciej",
  "EnvironmentName": "Robo_Maciej",
  "StartProcessCron": "0 0/1 * 1/1 * ? *",
  "StartProcessCronDetails": "{\"type\":0,\"minutely\":{\"atMinute\":1},\"hourly\":{},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"\"}",
  "ExecutorRobots": [
    {
      "Id": ****
    }
  ],
  "TimeZoneId": "UTC"
}

Note that you need the ReleaseId but not ReleaseKey.
Also, the StartProcessCronDetails seems to be mandatory, as it throws an error for me without it.

1 Like

Hi Maciej, could You translate pharse to UiPath Studio form?

Actually, I just search the Forum and it can be simpler:

{
  "Enabled":"False",
  "Name": "API",
  "ReleaseId":****,
  "ReleaseKey":"****",
  "ReleaseName": "HelloWorld_Robo_Maciej",
  "EnvironmentName": "Robo_Maciej",
  "StartProcessCron": "0 0/1 * 1/1 * ? *",
  "StartProcessCronDetails": "{\"advancedCronExpression\":\"0 0/1 * 1/1 * ? *\"}",
  "ExecutorRobots": [
    {
      "Id": ****
    }
  ],
  "TimeZoneId": "UTC"
}

Could you clarify what you mean by that?

@loginerror
I already explain,
when I enter the phrase 1:1 from SWAGGER to UiStudio, I get a syntax error.

For example:

postProcessSchedule.StartProcessCronDetails = "{\"type\":1,\"minutely\":{},\"hourly\":{\"frequencyInHours\":1,\"atMinute\":0},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"\"}"

When, I modify it, e.g .:
{ “Type”: 1 “minutely” {} “hourly”: { “frequencyInHours” 1 “atMinute” 0} “daily” {} “weekly”: { “weekdays” } “monthly”: { “weekdays” } “advancedCronExpression”: “”}
I get a syntax error that expects the end of the expression.

The thing is, I have no idea how to introduce this:

"{\"type\":1,\"minutely\":{},\"hourly\":{\"frequencyInHours\":1,\"atMinute\":0},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"\"}"

into a value for variable in the UiStudio.

Ach, I see.

First thing, please use the simpler option, I tested it and it works as well:
"StartProcessCronDetails": "{\"advancedCronExpression\":\"0 0/1 * 1/1 * ? *\"}",

Then, to make it work in Studio, you will have to escape all " with a second ", and then wrap the remaining query in "".

The result that should work for you:

"{\""advancedCronExpression\"":\""0 0/1 * 1/1 * ? *\""}"

(to arrive there, I pasted it in Notepad, then did a simple Replace All from " to "" and then wrapped the result in two "")

1 Like

@loginerror it works!
Thanks

Could you write where there is documentation available for building this type of syntax?

Will there be a training at UiPath Academy on building API queries using the UiPath.Web.Activities package?

In the orchestrator that I support, I set the minimum data range if I have 2 environments:

postProcessSchedule = New UiPathOrchestratorAPI.ProcessScheduleDto
in_ScheduleName is string variable
in_ProcessName is string variable
in_EnvironmentName is string variable
releaseID is string variable
robotID is string variable
in_Cron is string variable

postProcessSchedule.Name = in_ScheduleName
postProcessSchedule.ReleaseId = CLng(releaseID)
postProcessSchedule.ReleaseName = in_ProcessName + "_" + in_EnvironmentName
postProcessSchedule.EnvironmentName = in_EnvironmentName
postProcessSchedule.StartProcessCron = in_Cron
postProcessSchedule.StartProcessCronDetails = "{\""advancedCronExpression\"":\"""+in_Cron+"\""}"

postProcessSchedule.StartStrategy = 0

robotExecutor = New UiPathOrchestratorAPI.RobotExecutorDto()
robotExecutor.Id = cint(robotID)
postProcessSchedule.ExecutorRobots = {robotExecutor}
postProcessSchedule.TimeZoneId = in_TimeZoneId
postProcessSchedule.UseCalendar = False

Once a schedule is created, it cannot be edited. An Orchestrator message appears:

image

However, the task itself starts as instructed.

Hi @Adrian_Star

I believe the syntax to escape double quotation marks with double quotation marks is core to vb.net on which Studio is based (and as such is an ‘assumed knowledge’, but maybe @Madalina_Boboc can offer some advise on how to properly document that, maybe under the Web activity package).

I am not aware of any current plans to produce a tutorial strictly about it. However, I added your feedback to our internal tracking platform so that our Academy team can consider it.
One obvious way of learning more would naturally be to browse other people’s projects on our Forum.

Just to summarize the bug - after you create your schedule using only the minimum data, it works properly, but you cannot edit it via the user interface in Orchestrator?
If so, please share the version of Orchestrator that you are using.

One more thing - if you are working on an Enterprise edition, you can also contact our technical support for direct assistance :slight_smile:

@loginerror
I’m working on UiStudio 2019.10.1 Enterprise, Orchestrator is version 2018.4.4.

The bug is as you described. After creating a schedule with minimal data and with a more extensive structure, the problem is the same that once the schedule has been created in the orchestrator, it cannot be edited.
In addition, if I set the API option in Studio to schedule as Enable = False for the schedule.
This Schedule in the Orchestrator is active as green, i.e. as if it had moved with the Enable = True settings.

After some research it would seem like I was a bit too fast offering the shorted syntax for the StartProcessCronDetails field.
I found a bug in our tracker that has the exact same error message and was resolved by fixing that field.

It seems like you can find out the full correct input JSON by following these steps:

  1. Open the Network panel of the browser inspect panel.

    (here’s the Firefox one, but it can be any broswer)
  2. Add the queue item in Orchestrator. You will see the request happen in the browser panel:
    image
  3. After you click it, you will be able to see the entire input string:
    image

This is practical and allows you to always know what needs to be send to Orchestrator in the API call :slight_smile:

I think practically, you will want to take this output from the browser:

"{\"type\":5,\"minutely\":{},\"hourly\":{},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"0 0/1 * 1/1 * ? *\"}"

Escape all the double quotes except for the first one and the last one:

"{\""type\"":5,\""minutely\"":{},\""hourly\"":{},\""daily\"":{},\""weekly\"":{\""weekdays\"":[]},\""monthly\"":{\""weekdays\"":[]},\""advancedCronExpression\"":\""0 0/1 * 1/1 * ? *\""}"

And use that in your StartProcessCronDetails variable together with fields that are also included in the query when you inspect the http request. For me these were:
image
(I only removed my ReleaseId from the screenshot)

Here’s the same in text format:

{
	"Name": "nameofthetrigger",
	"InputArguments": "{}",
	"Enabled": true,
	"UseCalendar": false,
	"StartProcessCronDetails": "{\"type\":5,\"minutely\":{},\"hourly\":{},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"0 0/1 * 1/1 * ? *\"}",
	"StartProcessCron": "0 0/1 * 1/1 * ? *",
	"ExecutorRobots": [],
	"StopStrategy": null,
	"StopProcessExpression": "",
	"ReleaseId": ***,
	"ReleaseName": "HelloWorld_Robo_Maciej",
	"TimeZoneId": "UTC",
	"StartStrategy": -1,
	"StopProcessDate": null,
	"ExternalJobKey": ""
}
1 Like

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