#Rest API - filter snapshots by creation time

1 messages · Page 1 of 1 (latest)

flat hollow
#

Hello,
I'm trying to filter all snapshots older than X days, like in the CLI command: "volume snapshot show -create-time >1d", but it doesn't seems to work:
requests.get('https://cluster1.demo.netapp.com/api/private/cli/snapshot?fields=create-time?create_time>1d',headers=header,verify=False).json().get("records")

doesn't return any output, and also this one doesn't work:

response = CLI().execute("volume snapshot show", create-time>1d)
File "<stdin>", line 1
response = CLI().execute("volume snapshot show", create-time>1d)
^
SyntaxError: invalid decimal literal

Is there any way to achieve this?

Thanks

pliant ingot
#

Hello,
this looks like a Python syntax issue that you're running into. Try this instead:
response = CLI().execute("volume snapshot show", create_time=">1d")

What would be ideal is to use the correct endpoint to retreive this information rather than the CLI passthrough, which you're using.

Refer to the official python library documentation for the snapshot resource here: https://library.netapp.com/ecmdocs/ECMLP2886776/html/resources/snapshot.html

And the official REST API documentation here:
https://docs.netapp.com/us-en/ontap-restapi//ontap/get-storage-volumes-snapshots.html
There is a supported create_time field that you can use.