OData APIs

Joe Julian Updated by Joe Julian

Introduction

OData is a service within the HR application website, that allows integration partners to request specific data from any permitted table or view within the HR database.

Confidential clients

Administrators are expected to create their own confidential clients for their integrations partners, and assign permissions specifying exactly what data they can access. See the guide to setting up confidential clients for more information.

The confidential clients are authenticated using the Advanced SSO service. This service validates their credentials when they try to log in, and provides them with a token that they use for any request to the OData service.

Once the user has a valid token and requests data, the OData service uses Microsoft SQL Server Roles to ensure that they only get access to the data that the customer has specified. This is called Authorisation.

Authentication

We have implemented the OAuth 2.0 Client Credentials flow for the authentication of OData subscribers.

An Administrator will create a new confidential client in Advanced HR (as specified in our confidential client guide), and then provide the newly generated Client Id and Secret to the integrations partner.

They also provide the partner with the Authentication Token URL, which is where they will submit their credentials in exchange for a token.

Once the integrations partner has a valid token, they can make requests to the OData service. They add the token to the request’s Authorization header.

The token can be used repeatedly for any number of requests to the OData service, but they expire after about 5 minutes. After that, they will need to request a new token.

Authorisation

Once the integrations partner’s system has made a request to the OData service, their token is inspected to identify the confidential client and pass the Authorisation part of the request process.

If the user has permission to read the data that they have requested, they will receive a response in a JSON format.

Endpoint

HR now supports some basic OData queries through it’s new /odata endpoint.

Instead of using API endpoints which return a fixed list of fields with limited filtering, the OData endpoint allows applications to request any fields from any table or view in HR that they have access to, and filter, sort and paginate that data, in pretty much any way they need to.

To try out the OData endpoint, we recommend using postman. Postman allows you to log in to HR, and receive an access token, which can then be used to query the HR data using the guidelines below.

For details on how the HR data is secured for use with OData, see Advanced HR OData Security.

Requesting resources

The most basic request to /odata is for all the data to be returned from a single resource. A resource can be any HR table or view.

Here’s how to request all the data from the bank name table:

GET /api/v1/workplaces/{workplaceRef}/odata/bank_name_table

The result will be a JSON object such as this example:

{
    "count": 10,
    "nextLink": "?top=10&skip=10",
    "value": [
        {
            "Bank_Name": "Abbey National",
            "ID": 1,
            "TimeStamp": "AAAAAAEqqhY=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Alliance & Leicester",
            "ID": 2,
            "TimeStamp": "AAAAAAEqqhc=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Allied Irish Bank",
            "ID": 3,
            "TimeStamp": "AAAAAAEqqhg=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Bank of Ireland",
            "ID": 4,
            "TimeStamp": "AAAAAAEqqhk=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Bank of Scotland",
            "ID": 5,
            "TimeStamp": "AAAAAAEqqho=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Barclays Bank",
            "ID": 6,
            "TimeStamp": "AAAAAAEqqhs=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "cahoot",
            "ID": 7,
            "TimeStamp": "AAAAAAEqqhw=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Citibank",
            "ID": 8,
            "TimeStamp": "AAAAAAEqqh0=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Clydesdale Bank",
            "ID": 9,
            "TimeStamp": "AAAAAAEqqh4=",
            "RecordDescription": null
        },
        {
            "Bank_Name": "Co-operative Bank",
            "ID": 10,
            "TimeStamp": "AAAAAAEqqh8=",
            "RecordDescription": null
        }
    ]
}

As we have not specified any pagination settings, the default values of fetching the top 10 rows of data have been applied.

At the top of the response you can see a count and a nextLink property. The count property specifies the number of records returned in the response, and the nextLink property can be used to fetch the next set of records.

Queries

Applications can query the /odata endpoint with a series of query options.

For example, here’s how to request the 'full name' of the first five employees in the sales department

GET /api/v1/workplaces/{workplaceRef}/odata/current_employees?$top=5&$select=full_name, department&$filter=department eq 'sales'

Which might give the following result:

{
    "count": 5,
    "nextLink": "?select=full_name%2C%20department&filter=department%20eq%20%27sales%27&top=5&skip=5",
    "value": [
        {
            "full_name": "Harry Duley",
            "department": "Sales"
        },
        {
            "full_name": "Peter Harris",
            "department": "Sales"
        },
        {
            "full_name": "Andy Thomas",
            "department": "Sales"
        },
        {
            "full_name": "Mark Craden",
            "department": "Sales"
        },
        {
            "full_name": "Christine Peters",
            "department": "Sales"
        }
    ]
}

The query explained

Query section

Explanation

GET

A GET request asks the /odata endpoint to return data. Future functionality might include ‘DELETE’ or ‘PUT’.

/api/v1/workplaces/{workplaceRef}/odata/

This is the /odata endpoint

current_employees

The resource name. This can be any table or view in HR.

Spaces must be replaced with underscores

?

The first query must be prefixed with a question mark

$top=5

$top is a pagination setting. This query instructs OData to return the next 5 records only

&$select=full_name, department

All subsequent queries must be prefixed with the ampersand symbol '&'

$select is used to specify which fields OData is to include in its response

In this example, we’ve asked for only full_name and department to be returned.

Spaces in field names must be replaced with underscores

If you leave out the $select query, all fields in the resource are returned

Separate the field list with commas

&$filter=department eq 'sales'

$filter is used to filter the result set.

In this example we’ve specified that we only want results where the department equals 'sales'

Character values, e.g. 'sales' must be enclosed in single quotation marks

Numeric values are not quoted

Date values should be quoted and specified in complete date/time format, e.g. '1985-01-03T00:00:00' - note that all HR times are set to midnight: 00:00:00.

Other logical operators are

  • Equals - eq
  • Not Equals - ne
  • Greater than - gt
  • Greater than or Equal - ge
  • Less than - lt
  • Less than or Equal - le
  • And - and
  • Or - or
  • Not - not

The OData endpoint also supports some string functions:

  • contains - e.g. $filter=contains(date_of_birth,'1985')
  • startswith - e.g. $filter=startswith(surname,'A')
  • endswith - e.g. $filter=endswith(surname,'s')

Some other query options, not included in the previous example, include:

Query option

Explanation

$orderby

Allows users to specify the order of the results e.g.

$orderby=surname desc

use desc or asc to specify descending or ascending order

$top and $skip

$top specifies how many records OData is to return

$skip specifies how many records to skip/exclude from the result

These are used for pagination. If you want results in groups of 10 records, and require page 3, you’d specify $top=10&$skip=20

Was this article useful?

APIs for integration

Contact