Using the API to find members unsubscribed within a time period - problem

  • 1
  • Problem
  • Updated 4 months ago
  • Solved
Hi, as can be seen from the title, I'm trying to use the API to search for members unsubscribed within a time period. However, I'm running into some problems and am finding some parts of the documentation a bit unclear. The docs say that the "unsubscribed" filter " takes a date filter on the timestamp of the opt-out action" but don't really explain it in more detail or give an example. I've tried constructing searches in multiple different ways:

["unsubscribed", "between", "2016-12-01", "2017-07-01"]
["unsubscribed", "between", {"year": "2016", "day": "1", "month": "12"}, {"year": "2017", "day": "1", "month": "7"}]
["unsubscribed", "between", "@D:2016-12-01T00:00:00", "@D:2017-07-01T00:00:00"]

The searches are created but once I try actually running them, I keep getting a
500 Internal Server Error. What am I doing wrong? What date format should be used and how should I structure the date filter? Thanks in advance!
Photo of zeksm

zeksm

  • 2 Posts
  • 0 Reply Likes

Posted 5 months ago

  • 1
Photo of Andrew Heuback

Andrew Heuback, Official Rep

  • 141 Posts
  • 12 Reply Likes
Hey there! You can find an example of a search with date here:
http://api.myemma.com/api/external/searches.html#post--%23account_id-searches

The format for date is listed in the example like this:
"opened", 123249, "between", "2011-01-22, 2011-01-31"

In your example, you had quotes around each individual date, when it should be around the range of dates.

You can also find additional date syntax here:
http://api.myemma.com/member_search.html#dates

Let me know if you have any further questions!
(Edited)
Photo of zeksm

zeksm

  • 2 Posts
  • 0 Reply Likes
The thing is, I already tried that, but then I immediately get a 500 Internal Server Error when creating the search (not just running it) and the search thus doesn't even get created! My guess is that that's just a typo in the docs. So unfortunately that's not really a solution to my problem.

I've also read that part about the date syntax and tried it - you can see the ["unsubscribed", "between", {"year": "2016", "day": "1", "month": "12"}, {"year": "2017", "day": "1", "month": "7"}] example above. Though I'm confused about that too a bit, since it talks about {"day", 31}, but then about {"dow": 2} and about a date being a hash with keys, and in the interval section above it it's {"year": 2, "day": 4} . So I'm not sure whether I should separate "key" and value with a comma or a colon? And if use a comma, how do I structure a full date with year, month, day?
Photo of Andrew Heuback

Andrew Heuback, Official Rep

  • 141 Posts
  • 12 Reply Likes
Hey there! I did some testing with my colleagues and we were able to run a working search; here is an example:

  {
    "criteria": 
        ["and", 
         ["and",     
            ["unsubscribed mailing", "gt", "2017-12-31"]
            ]
         ]
  }

I'm also working on updating our API docs to make this more clear. Let us know if you need a further hand!