Ask the Community
Groups
Sorting and filtering in the IT Glue API - Connect IT Community | Kaseya
<main> <article class="userContent"> <p><em>For partners subscribed to the current Enterprise plan.</em></p> <p>A lot of the time, when you're making calls to the IT Glue API, there will be a lot of results to return. For that reason, you will sometimes want to filter or sort the results to make sure you're seeing the information you want.</p> <h3 data-id="filtering">Filtering</h3> <p>Filters are simple methods that modify the output of numbers and strings, like date filtering, using brackets.</p> <p>For example, this GET request will return all user metrics:</p> <ul><ul><li><em>GET /users_metrics</em></li> </ul></ul><p>You will probably find this produces too much information. This next GET request will return all user metrics for a specific time frame (one month):</p> <ul><ul><li><em>GET /users_metrics?filter[date]=2017-02-01,2017-02-28</em></li> </ul></ul><p>This will probably still be too much information. To get more specific, you can combine filtering conditions using & (ampersand). For example, this GET request will return all user metrics within a specific time frame for a specified user:</p> <ul><ul><li><em>GET /users_metrics?filter[date]=2017-02-01,2017-02-28&filter[user_ID]=1234</em></li> </ul></ul><div> <p><strong>Note:</strong> Commas in filters can be escaped with a backslash (\). For example, an organization named <em>Kub, Reynolds and Gibson</em> can be filtered by name by adding a backslash before the comma as demonstrated below:</p> <code class="code codeInline" spellcheck="false" tabindex="0">filter[name]=Kub\, Reynolds and Gibson</code> </div> <p>All supported filter parameters can be found with their relevant GET endpoints in the <a href="/home/leaving?allowTrusted=1&target=https%3A%2F%2Fapi.itglue.com%2Fdeveloper%2F" rel="noopener noreferrer nofollow">developer documentation</a>. Note that filtering in nested relationship routes is not possible.</p> <p>Dates should be provided in <a href="/home/leaving?allowTrusted=1&target=http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3339.txt" rel="noopener noreferrer nofollow">RFC3339</a> format in UTC timezone: YYYY-MM-DDTHH:MM:SSZ. You may omit the time and timezone if desired.</p> <h3 data-id="sorting">Sorting</h3> <p>You can order the API results using supported resource-specific parameters.</p> <p>For example, you might need to return all users ordered by creation date. Your GET would look like this:</p> <ul><ul><li><em>GET /users?sort=created_at</em></li> </ul></ul><p>To return the results in descending order (recent users on top), use this:</p> <ul><ul><li><em>GET /users?sort=-created_a</em></li> </ul></ul><p>You can also add filtering conditions using & (ampersand).</p> <p>Related articles</p> <ul><li><a rel="nofollow" href="/home/leaving?allowTrusted=1&target=https%3A%2F%2Fkaseya.vanillacommunities.com%2Fkb%2Farticles%2Faliases%2Fitglue%2Fhc%2Fen-us%2Farticles%2F360004938078">Getting started with the IT Glue API</a></li> </ul> </article> </main>