Our reporting API supports a number of parameters added to the URL. These can be used to add filters or rows to the report. They can also be used to specify the format, data source, name, layout, and template of the report. This API endpoint cannot be used to create new page templates or layouts directly (users should create these templates/layouts in the UI for use in direct calls to the API).
This article focuses on the calculated values in the query URL, specifically rowDimensions and filters. Before reading, please familiarize yourself with Getting Started and Authentication as this request requires authentication.
Breaking down a report query
When requesting a report from the UI, the URL of the progress screen will have details about the report. This contains both plaintext and base-64 encoded data for the GET request.
- plaintext fields
- format: output format of report [xls|pdf|word|csv|tsv|json]
- data: short for the dataset of the report (see Dataset in User Interface)
- attrName: internal name for the report
- pageTemplate: layout of the page to use (see Formatting in User Interface)
- reportTitle: visible name of the report (affects output filename) base-64 encoded fields
- rowDimensions: description of dimensions used in the report (u8int array)
- filters: description of filters applied to report (JSON array/string)
You can read more about basic reporting API requests here.
rowDimensions is an extremely concise description of the row dimensions used in the report. This is still encoded base-64 for the GET request, but it is used by our report engine directly and is not easily modified. Users of the reporting API should use dimension values generated by the User Interface.
filters are the bread-and-butter of reports. Our API is built to allow easy changes to the value of filters when making requests to the reporting API. The above example is decoded below:
[ [ "productProductUrl", "/ACCOUNTPATHCOMPONENT/api/product/4x8%20DJ%2015" ], [ "FormulaFilter", "lookup(\"productStockAvailableToPromiseCaseEquivalents\") > 10" ] ]
Filters are always defined in an array. The first value is the field/type and the second value is the filter value itself. There are two main categories of filters: built-in and formula filters.
It is to your advantage to use built-in filters. They may take advantage of internal data structures and are much more efficient at filtering data. These can be identified by the filters that exist in the User Interface (everything except "Formula Filter" in the Filters section, see image below).
There are several types of filters built-in for our system, and we add/optimize more fields every day. The above filter for
productProductUrl accepts a string as the filter value. Other string values may be in the form of a single-element array. Numeric filters are usually in the form of an array of two values (
For example, a date range filter on order date on the order dataset (
orderOrderDate) can be expressed as a type of range filter using the ISO8601 date format:
Date range filters can also be expressed as a range object, specifying a duration, offset, and length:
This is relative to the current UTC date. The available values for duration are [week|isoweek|month|year]. This value defines the units for the offset and length. The above example calls for the last ISO week (Monday through Sunday). If it used week instead, it would be Saturday through Sunday.
To find the format of a specific built-in filter, we recommend using the filter in an existing report in the User Interface and decoding the string. This can be done quickly in the browser using the developer console (pressing F12) and parsing the URL using the following snippet:
var filters = "... paste filters value here from URI ..."; console.log(window.atob(window.decodeURIComponent(filters)));
Note that I use
window.decodeURIComponent() before decoding from base-64 to a binary string. This is due to characters allowed in base-64 encoding but not allowed in HTTP URIs. Most libraries will handle this when making programmatic GET requests.
Formula filters offer the ability to filter values not currently optimized/built-in to our system. These can add impressive functionality to the reporting API, but may not be as efficient on larger data sets (leading to timeouts for requests).
Fields available to use depend on the data set. Refer to the User Interface on which fields can be used by creating a "Formula filter" in the Filters section and clicking on the drop-down to the right of the formula entry.
Formulas that evaluate to true for a row are included. These formulas can contain logical expressions, math operators, basic functions, and data type conversions. Here is a complete reference.
Note that double-quotes inside of the formula string have to be escaped by a
Filters are encoded using base-64 and sent as parameters of the GET request in the URI. Here are some examples of encoding in base-64 in a few popular languages: