The WATS REST API can be used to get reports similar to Test Reports in Reporting. There are two main ways to get header information about test reports from the REST API: Query header and UUTReport.
Query header
An OData query can be used to get reports matching the specified filter. By default it returns the 10 most recent reports ordered by newest.
GET https://your-wats-server/api/report/query/header
See also the REST API documentation to see all the properties you can filter on.
$filter
Use the $filter query parameter to filter reports.
- Matching part number and revision:
- GET https://your-wats-server/api/report/query/header?$filter=partNumber eq 'XYZ123' and revision eq '2'
- Matching test result (Passed, Failed, Error, or Terminated) and report type (T for UUT or R for UUR):
- GET https://your-wats-server/api/report/query/header?$filter=result eq 'Failed' and reportType eq 'T'
- Matching time period:
- GET https://your-wats-server/api/report/query/header?$filter=Start gt 2018-01-01T00:00:00Z and Start lt 2018-12-31T23:59:59Z
- Using functions for more complicated filtering:
- GET https://your-wats-server/api/report/query/header?$filter=startswith('ABC', serialNumber)'
$top
Use the $top query parameter to specify how many reports shall be returned. The default is 10. If more than $top matches the filter, the first $top will be used, by default sorted by newest report.
GET https://your-wats-server/api/report/query/header?$top=100
- Combine with $filter:
- GET https://your-wats-server/api/report/query/header?$filter=partNumber eq 'XYZ123' &$top=1000
$skip
To get every report matching a filter, send multiple requests using $top and $skip to paginate the result until no results are returned.
- GET https://your-wats-server/api/report/query/header?$filter=partNumber eq 'XYZ123'&$top=1000&$skip=0
- GET https://your-wats-server/api/report/query/header?$filter=partNumber eq 'XYZ123'&$top=1000&$skip=1000
- GET https://your-wats-server/api/report/query/header?$filter=partNumber eq 'XYZ123'&$top=1000&$skip=2000
$orderby
Use the $orderby query parameter to change the order of the results and which reports are returned with regards to $top and $skip. The default is start. Use asc(ending) or desc(ending) after the property to set sort direction, if not specified asc is used.
- Oldest reports first:
- GET https://your-wats-server/api/report/query/header?$orderby=start asc
- Lowest serial number first:
- GET https://your-wats-server/api/report/query/header?$orderby=serialNumber desc
$select
Use $select to limit which fields are returned. May make queries faster because it has to find less data.
- Only returns serial number, part number, and revision:
- GET https://your-wats-server/api/report/query/header?$select=serialNumber,partNumber,revision
$expand
Use $expand to include extra data items with each report, like misc info, sub units, and assets.
- Include misc info in result:
- GET https://your-wats-server/api/report/query/header?$expand=miscInfo
- Include misc info and sub units:
- GET https://your-wats-server/api/report/query/header?$expand=miscInfo,subUnits
Reports can be filtered by expanded items. Only reports that have at least one matching expanded item is returned, but all expanded items are included.
- Reports that have at least one misc info with description 'abc':
- GET https://your-wats-server/api/report/query/header?$filter=miscInfo/any(mi: mi/description eq 'abc')&$expand=miscInfo
- Reports that have at least on sub unit with the same serial number as the report
- GET https://your-wats-server/api/report/query/header?$filter=subUnits/any(su: su/serialNumber eq serialNumber)&$expand=subUnits
NOTE: The names "mi" and "su" are defined by you and can be anything. They are used to separate expanded item fields from report fields.
The expanded items can be filtered with $filter, sorted with $orderby, paginated with $top and $skip, and returned fields can be limited with $select. These options do not change which reports are returned, only which expanded items are returned. A report with no items matching the expanded filter is still returned.
- Include misc info where the misc info description is 'abc':
- GET https://your-wats-server/api/report/query/header?$expand=miscInfo($filter=description eq 'abc')
- Include sub units sorted by lowest sub unit serial number first, with only serial number and part number:
- GET https://your-wats-server/api/report/query/header?$expand=subUnits($orderby=serialNumber asc;$select=serialNumber,partNumber)
For more information about OData and how to use it to query see http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html
UUTReport
The UUTReport is the same as the UUT Grid in Test Reports in Reporting, but available as a REST API. It takes the WATS Filter as input in the body of the request. For how to use the WATS Filter, see the documentation in WATS Help under REST API -> WATS Filter.
POST https://your-wats-server/api/app/uutreport
By default it returns the top 1000 reports. This can be changed by setting the topCount field in the filter. It does not support paginating. It does not support changing the sort order of the reports.
Top result limit
These APIs have a default limit on how many reports they return which can be increased, but not removed. This limit is there to limit resource usage and increase speed. In the most common cases 1000 reports is enough. Without the limit someone could make a program or similar that is constantly fetching more data than it needs and slowing down WATS for all users. When there is a limit that they need to take steps to bypass, it makes it more likely that they actually need the data.
WSXF
To retrieve a specific report use the GET WSXF API with the report's unique identifier (Guid):
GET https://your-server-address/api/report/wsxf/3CCB709E-5155-4D62-9402-48DF8F576D7A
Refer to this article for details on the WSXF format.
WSJF
To retrieve a specific report use the GET WSJF API with the report's unique identifier (Guid):
GET https://your-server-address/api/report/wsjf/3CCB709E-5155-4D62-9402-48DF8F576D7A
Refer to this article for details on the WSJF format.
Comments
2 comments
Thank you for the API to let me get serial number
Restrict to a specified Serialnumber:
https://your-server-address/wats/api/report/query?$filter=SN eq '123-45678'
I have been struggeling with Python + robobrowser to get automated report export/extracts from a specific serial number. Your API makes things MUCH easier :-)
Thanks
-Brian
Hi Tom,
"The following query will return the 10 most recent reports from the database:"
Is there a way to circumvent this? to change to all reports?
Please sign in to leave a comment.