1

I am retrieving compute engine snapshots from google projects using rest api in postman. I want to retrieve snapshots that were created after a certain time stamp value using the filter, If I pass the "=" as operator it works like the below one:

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

I wanto to filter records which are larger than a particular timestamp so I use this

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

or

(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

But even for < or > operator I am getting this:

{
    "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"
            }
        ]
    }
}

Can anyone please suggest a solution?Thanks

Update

My end goal is to create a snapshot report in data-studio, so is there any way I can get the rest api snapshot data to bigquery or any other datasource through which I can create this report?

user1403505
  • 895
  • 2
  • 19
  • 42
  • From the docu: `The value must be a string, a number, or a boolean. The comparison operator must be either =, !=, >, or <`. Your passing in a string together with a comparison operator (`>`): I have some doubts that his works. – Christian Baumann Oct 02 '20 at 10:20
  • Yes, but since they have given > or < should work, it should work, i assume. even "=" is working – user1403505 Oct 02 '20 at 10:51
  • 2
    You can check if two strings are equal via `=`, but it's not possible to compare strings via `<`. I guess, comparison only works for numbers. – Christian Baumann Oct 02 '20 at 11:01
  • Yes , but I have to filter timestamp values , is there any other way in the api? – user1403505 Oct 02 '20 at 11:03
  • 1
    Can you use gcloud CLI or the REST API is a requirement? – guillaume blaquiere Oct 02 '20 at 12:29
  • i need to use google-python-api library in the end application, but for testing purposes i need to use rest api . – user1403505 Oct 02 '20 at 13:45
  • 1
    Hi @user1403505 as you are comparing strings, the API will not answer in the way you want. You will need to manualy filter the creation date of your snapshot once you have the full list retrieved. – gso_gabriel Oct 05 '20 at 13:19

1 Answers1

1

Posting this as Community Wiki based in the comments.

As you are comparing strings, unfortunately, the API will not answer in the way you want. You will need to manualy filter the creation date of your snapshot once you have the full list retrieved. This way, you won't be able to be filtering the data while returning it, but only after you retrieve the data from the instance.

gso_gabriel
  • 4,199
  • 1
  • 10
  • 22