【问题标题】:How to filter google rest api json response for snapshot using creationtimestamp field?如何使用 creationtimestamp 字段过滤快照的 google rest api json 响应?
【发布时间】:2020-10-02 10:14:55
【问题描述】:

我正在使用 postman 中的 rest api 从谷歌项目中检索计算引擎快照。我想使用过滤器检索在某个时间戳值之后创建的快照,如果我将 "=" 作为运算符传递,它 works 如下所示:

https://compute.googleapis.com/compute/v1/projects/my-project/global/snapshots?filter=(creationTimestamp="2020-05-25T06:06:45.366-07:00")

我想过滤大于特定时间戳的记录,所以我使用它

 https://compute.googleapis.com/compute/v1/projects/my-project/global/snapshots?filter=(creationTimestamp>"2020-05-25T06:06:45.366-07:00") 

(creationTimestamp>="2020-05-25T06:06:45.366-07:00") (Here I read in the documentation that we can only use !=, >, or <. so I am not sure whethere i can use >= or <=)

https://cloud.google.com/compute/docs/reference/rest/v1/snapshots/list

但即使对于 运算符,我也得到了这个:

{
    "error": {
        "code": 400,
        "message": "Invalid value for field 'filter': 'creationTimestamp>2020-05-25T06:06:45.366-07:00'. Invalid list filter expression.",
        "errors": [
            {
                "message": "Invalid value for field 'filter': 'creationTimestamp>2020-05-25T06:06:45.366-07:00'. Invalid list filter expression.",
                "domain": "global",
                "reason": "invalid"
            }
        ]
    }
}

谁能提出解决方案?谢谢

更新

我的最终目标是在 data-studio 中创建一个快照报告,那么有什么方法可以将其余的 api 快照数据获取到 bigquery 或任何其他可以创建此报告的数据源?

【问题讨论】:

  • 来自文档:The value must be a string, a number, or a boolean. The comparison operator must be either =, !=, &gt;, or &lt;。您将字符串与比较运算符一起传递(&gt;):我对他的作品有些怀疑。
  • 是的,但既然他们给出了 > ​​或
  • 你可以通过=检查两个字符串是否相等,但是不能通过&lt;比较字符串。我猜,比较只适用于数字。
  • 是的,但是我必须过滤时间戳值,api中还有其他方法吗?
  • 您可以使用 gcloud CLI 还是需要 REST API?

标签: google-cloud-platform postman google-compute-engine google-compute-api


【解决方案1】:

将此作为基于 cmets 的社区 Wiki 发布。

不幸的是,当您比较字符串时,API 不会以您想要的方式回答。检索到完整列表后,您将需要手动过滤快照的创建日期。这样,您将无法在返回数据时对其进行过滤,而只能在您从实例中检索数据之后进行过滤。

【讨论】:

    猜你喜欢
    • 2016-05-11
    • 2021-06-10
    • 2018-12-20
    • 2016-10-06
    • 2020-08-09
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    相关资源
    最近更新 更多