Azure自动化作业OData $ filter

时间:2018-06-17 08:20:42

标签: azure odata azure-automation azure-runbook

背景

  • 我有一个应用程序,它使用REST API
  • 获取Runbook作业列表
  • 我想在属性参数上应用$ filter(最后参见JSON)。参数类型为IDictionary<string,string>

问题

  • $ filter适用于大多数属性,但对IDictionary<string,string>
  • 失败
  • 这就是我正在尝试的https://management.azure.com/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Automation/automationAccounts/XXX/jobs?$filter=properties/parameters/any(keyValue: keyValue/owner eq 'Adam@test.com')&api-version=2015-10-31
  • 请求失败,错误为{ "code": "BadRequest", "message": "Could not find a property named 'owner' on type 'System.Collections.Generic.KeyValuePair_2OfString_String'." }

问题

  • 是否可以过滤我正在尝试的内容?
  • 如果是,那么我做错了什么?

我要应用过滤器的JSON响应

&#13;
&#13;
"value": [
        {
            "id": "/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Automation/automationAccounts/XXX/jobs/XXX",
            "properties": {
                "jobId": "XXX",
                "runbook": {
                    "name": "HelloWorldRunbook"
                },
                "schedule": null,
                "provisioningState": "Succeeded",
                "status": "Completed",
                "creationTime": "2018-06-17T05:44:12.197+00:00",
                "startTime": "2018-06-17T05:44:21.227+00:00",
                "lastModifiedTime": "2018-06-17T05:44:43.43+00:00",
                "endTime": "2018-06-17T05:44:43.43+00:00",
                "jobScheduleId": "7fc134ac-d8bd-464e-b041-6e6b50f83f0c",
                "runOn": null,
                "parameters": {
                  "Owner": "Adam@test.com",
                  "mailBox": "test_mailbox@test.com"
             }
            }
 ............removed for brevity
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

当我尝试运行List Job By Automation Account Rest API时,响应正文中没有返回任何属性parameters

  

如果是,那么我做错了什么?

  ...
  "parameters": {
                  "Owner": "Adam@test.com",
                  "mailBox": "test_mailbox@test.com"
             }
   ...

但是根据你提到的响应json格式,参数属性是一个对象而不是一个字典,所以你可以使用$filter=properties/parameters/Owner eq 'Adam@test.com'来确保参数存在。

 Get https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs?api-version=2015-10-31&$filter=properties/parameters/Owner eq 'Adam@test.com'