0

I'm trying to filter the recent softlayer events by data via the API, for example setting up the following filter to get events modified in the last 48 hours

f := filter.Path("modifyDate").DateAfter(time.Now().Add(-48 * time.Hour).Format("01/02/2006 15:04:05")).Build()

And I call it via

resp, err := AccountService.Filter(f).GetRecentEvents()

I have tried time formats with date and time and just date in the form mm/dd/yyyy With debug enabled I can see this generates the following filter

2018/04/09 17:29:45 {"modifyDate":{"operation":"greaterThanDate","options":[{"name":"date","value":["04/07/2018 17:29:45"]}]}}
2018/04/09 17:36:22 [DEBUG] Request URL:  GET https://api.softlayer.com/rest/v3/SoftLayer_Account/getRecentEvents.json?objectFilter=%7B%22modifyDate%22%3A%7B%22operation%22%3A%22greaterThanDate%22%2C%22options%22%3A%5B%7B%22name%22%3A%22date%22%2C%22value%22%3A%5B%2204%2F07%2F2018+17%3A36%3A22%22%5D%7D%5D%7D%7D
2018/04/09 17:36:22 [DEBUG] Parameters:
2018/04/09 17:36:23 [DEBUG] Status Code:  200

Unfortunately this always returns the same results. How should I construct my query for what I'm trying to do?

Al S-M
  • 48
  • 4

1 Answers1

1

You could try the following example:

f := {"recentEvents": {"modifyDate": {"operation": "greaterThanDate","options": [{"name": "date","value": ["03/21/2018 17:29:44"]}]}}}

resp, err := service.Filter(f).GetRecentEvents()

For more information you could review the following:

https://github.com/softlayer/softlayer-go

Fernando Iquiza
  • 531
  • 3
  • 7
  • That works great thanks, how did you know that the filter needed an outer `"recentEvents"`? – Al S-M Apr 10 '18 at 08:35
  • 1
    No problem, glad to help. And about the outer "recentEvents" it`s just the method in the request, taking out the first word and beginning it with lowercase, so in example if you used "getVirtualGuests" method, the filter should begin with "virtualGuests". You can get further information on the following site: https://softlayer.github.io/article/object-filters/ and get more examples like that. – Fernando Iquiza Apr 10 '18 at 15:04
  • 1
    @AI S-M, you can also review the post https://stackoverflow.com/questions/41186972/how-to-use-object-filter-with-softlayer-rest-api to know about how to use filters – Albert Camacho Apr 10 '18 at 15:29