uipath - 将文件路径作为输入参数传递给 Orchestrator API StartJobs 时验证失败
问题描述
我正在尝试(Ex: C:\Document\Report.txt)
通过 uipath orchastrator api 使用文件名路径作为参数。我尝试了不同的方法,在每种方法中我都收到错误请求错误"{"message":"Argument Values validation failed.","errorCode":2003,"resourceIds":null}"
下面是我的示例代码
FileListUploaded ="C\\Documents\\report.txt";
string parameter1 = "{\"startInfo\": {\"ReleaseKey\": \"xxxxx-xxx-xxx-xxx-xxxxxx\"," +
"\"RobotIds\": [xxxxx]," +
"\"JobsCount\": 0," +
"\"InputArguments\": \"{ "+
"\\\"reports_or_other_files\\\": \\\" + FileListUploaded + \\\"}\"}}";
request_startRobot.AddParameter("application/json; charset=utf-16", parameter, ParameterType.RequestBody);
IRestResponse response_startRobot = client_startRobot.Execute(request_startRobot);
解决方案
看起来有点乱,但看起来你没有正确引用和转义你的 JSON。
我可能会建议构建一个数组并将其序列化为 JSON 以使其更易于阅读,或者使用 HEREDOC 或字符串格式。如果您确实继续将 JSON 正文字符串连接在一起,请转储结果以查看它是如何组合在一起的。
JSON 的最终结果应该类似于
{
"startInfo": {
"ReleaseKey":"{{uipath_releaseKey}}",
"Strategy":"JobsCount",
"JobsCount":1,
"InputArguments":"{\"reports_or_other_files\":\"C:\\\\Documents\\\\report.txt\"}"
}
}
使用 InputArguments:
- 看起来你缺少一些引号
- 可能需要在 FileListUploaded 变量中双重转义反斜杠
- 路径中的 C 后缺少冒号