Limit "GET /v2/actions" by date range?

September 28, 2017 100 views
API

Hello, I was wondering if there was, or could be, a way to limit the returned actions from the /v2/actions endpoint, by some kind of date range. It would be nice to be able to only retrieve actions from say, the last day, or week, or something. For example:

GET /v2/actions?since=<some date string/# of seconds since epoch, etc>&until=<another date string of some kind>

would limit the results to be between the since' anduntil' parameters.

Is something like this possible and I'm just not seeing it? Or could it easily be added?

1 Answer

As far as I'm aware there is no such option. You will have to develop it yourself.

  • I mean, I can filter the returned results by a date range, but I was hoping there would be a way to cut down on the number of requests, since I'd have to make as many requests as necessary to retrieve all the actions for an account, then do the filtering only after downloading all of them.

    • You can't filter by a date, but if you just want to cut down number of entries in the response, you can play around with list options.

      So what you can do.. DO API supports paging. You can pass the number of entries and number of page you want to get.

      If you would execute:

      • curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer token" "https://api.digitalocean.com/v2/actions?page=1&per_page=10"

      You would only get 10 records, instead of all records.
      However, I don't know is it defined which 10 records you'll get. You can get last 10 records, or first 10 records.
      As far as I tested, it returns latest records.

      If you need to obtain the last page, you would have to execute one arbitrary request to get the link of the last page, and then execute that link.

      Still, you can't list by the date, but it could help you to cut down the number of responses.

      The following API resources could be helpful to you, if you didn't already found them:
      DigitalOcean API — Actions
      DigitalOcean API — Meta and Links

Have another answer? Share your knowledge.