Skip to content

SolarQuery API global objects

Matt Magoffin edited this page Dec 4, 2013 · 13 revisions

This page lists objects used throughout the SolarQuery API.

Paged results object

Many API methods can return large sets of data, but SolarQuery will break up the results into smaller paged response objects that contain just a subset of the overall data. The response object contains details on the total number of available results along with the starting offset of the returned results:

{
  "success": true,
  "data": {
    "results": [...],
    "totalResults": 2384790,
    "startingOffset": 0,
    "returnedResultCount": 250
  }
}```

In the preceding example, **2384790** results are available, but only the first **250** results have been returned in the `data` array. To get the next set, or _page_, of results you'd call the same method again but provide a 0-based starting offset for the desired first result. In this case, an offset of **250** would return the next page, which would result in a response like:

```json
{
  "success": true,
  "data": {
    "results": [...],
    "totalResults": 2384790,
    "startingOffset": 250,
    "returnedResultCount": 250
  }
}```

# Paged query parameters

For API methods that return paged results objects, the following query parameters are used to specify the page attributes:

<table>
	<tr>
		<th><code>max</code></th>
		<td>A positive integer for the maximum number of results to return in the response. SolarQuery might limit the number of returned results and ignore this value if it is too large.</td>
	</tr>
	<tr>
		<th><code>offset</code></th>
		<td>A non-negative integer for the starting offset of the results to return in the response. When combined with the <code>max</code> parameter you can get individual _pages_ of results from the overall result set.</td>
	</tr>
</table>

# Sort query parameters

For API methods that support sorting the result, an array of sort descriptors can be provided on the `sorts` query parameter. Array parameters must be specified as `sort[x].y` where _x_ is a 0-based index that specifies the order of the sort descriptor and _y_ is the sort descriptor property as detailed here:

<table>
	<tr>
		<th><code>sortKey</code></th>
		<td>The name of the property to sort the results by. Typically this will correspond to the name of an attribute in the returned result objects. For example to sort a location search by name, a query parameter like <code>sorts[0].sortKey=locationName</code> might be appropriate. Consult the documentation for individual API methods for details on the supported <code>sortKey</code> values.</td>
	</tr>
	<tr>
		<th><code>descending</code></th>
		<td>A boolean indicating the sort should be in descending (<em>true</em>) or ascending (<em>false</em>) order. By default this value is <em>false</em> so sorts will be applied in ascending order if this is not specified.</td>
	</tr>
</table>

Clone this wiki locally