title: How to include / exclude filter statement in R httr query for Localytics
body: <p>I can successfully query data from Localytics using R, such as the following example:</p>
  
  <pre><code>r &lt;- POST(url = "https://api.localytics.com/v1/query,
             body=list(app_id=&lt;APP_ID&gt;,
                       metrics=c("occurrences","users"),
                       dimensions=c('a:URI'),
                       conditions=list(day = c("between", "2020-02-11", "2020-03-12"),
                                       event_name = "Content Viewed",
                                       "a:Item URI" = "testing")
             ),
             encode="json",
             authenticate(Key,Secret),
             accept("application/json"),
             content_type("application/json"))
  stop_for_status(r)
  </code></pre>
  
  <p>But what I would like to do is create a function so I can do this quickly and not have to copy/paste data. </p>
  
  <p>The issue I am running into is with the line <code>"a:Item URI" = "testing"</code>, where I am filtering all searches by the Item URI where they all equal <code>"testing"</code>, but sometimes, I don't want to include the filter statement, so I just remove that line entirely.</p>
  
  <p>When I wrote my function, I tried something like the following:</p>
  
  <pre><code>get_localytics &lt;- function(appID, metrics, dimensions, from = Sys.Date()-30, 
                             to = Sys.Date(), eventName = "Content Viewed",
                             Key, Secret, filterDim = NULL, filterCriteria = NULL){
  
    r &lt;- httr::POST(url = "https://api.localytics.com/v1/query",
                    body = list(app_id = appID,
                                metrics = metrics,
                                dimensions = dimensions,
                                conditions = list(day = c("between", as.character(from), as.character(to)),
                                                  event_name = eventName,
                                                  filterDim = filterCriteria)
                                ),
                    encode="json",
                    authenticate(Key, Secret),
                    accept("application/json"),
                    content_type("application/json"))
    stop_for_status(r)
    result &lt;- paste(rawToChar(r$content),collapse = "")  
    document &lt;- fromJSON(result)                                      
    df &lt;- document$results
    return(df)
  }
  </code></pre>
  
  <p>But my attempt at adding <code>filterDim</code> and <code>filterCriteria</code> only produce the error <code>Unprocessable Entity</code>. (Keep in mind, there are lots of variables I can filter by, not just <code>"a:Item URI"</code> so I need to be able to manipulate that as well.</p>
  
  <p>How can I include a statement, where if I need to filter, I can incorporate that line, but if I don't need to filter, that line isn't included?</p>