SAP Knowledge Base Article - Public

2675265 - OData API: Using the $top and $skip tokens

Symptom

In this document we will review the '$top' and '$skip' tokens in the context of constructing OData API Query structures.

Occasionally when running OData API queries, you do not always retreive the number of records you are expecting. For example, you are querying the EmployeeTime records for an employee. This employee has 5 EmployeeTime records, but the query is only returning 1 record.

Environment

  • BizX
  • OData API

Reproducing the Issue

1. Create a query - EmployeeTime as an example as REQUEST:

   https://api2.successfactors.eu/odata/v2/EmployeeTime?$select=externalCode,userId,startDate,endDate,cust_StartTime,cust_EndTime,approvalStatus&$filter=lastModifiedDateTime%20ge%20datetimeoffset%XXXXXX-XX-XXTXX:XX:XXZ

2. View RESPONSE:

  You are not getting the number of records expected.

Cause

  • For the query there's more than one page data to be returned.
  • For each page, the maximum page size is 1000.
  • Please use $top and $skip token to fetch the pages of data.

Resolution

The $top Keyword:

   Example:

   http://<hostname>/odata/v2/User?$top=5

   The first 5 User Entries are returned where the Collection of User Entries are sorted using a schema determined by the OData service.

The $skip Keyword:

   Example:

   http://<hostname>/odata/v2/User(1)/proxy?$skip=2

   The set of proxy Entries (associated with the User Entry identified by key value 1) starting with the third User.

Query with $top and $skip:

      Using the $top and $skip options together in a request URI creates a pagination query. The response is a subset of the whole result, from $skip to $top. $skip indicates the starting row for the query. $top limits the size of the query.

   For example, if the URI uses $top=50, $skip=20, the response is a subset from numbers 21 to number 70 of the whole result set.

EmployeeTime with $top and $skip tokens example:  

   For example, to fetch the second page with 1000 records:

   https://api2.successfactors.eu/odata/v2/EmployeeTime?$select=externalCode,userId,startDate,endDate,cust_StartTime,cust_EndTime,approvalStatus&$filter=lastModifiedDateTime%20ge%20datetimeoffset%XXXXXX-XX-XXTXX:XX:XXZ%XX&$top=1000&$skip=1000

See Also

SAP SuccessFactors HCM Suite OData API: Developer Guide:

https://help.sap.com/doc/a7c08a422cc14e1eaaffee83610a981d/1805/en-US/SF_HCM_OData_API_DEV.pdf

Keywords

  • OData API
  • $top
  • $skip
, KBA , LOD-SF-INT-ODATA , OData API Framework , LOD-SF-INT , SF Integrations - EC Payroll, Boomi/ HCI, API , How To

Product

SAP SuccessFactors HCM Core 1805