Connecting to OData

Version 22.0.8486


Connecting to OData


The Connect OData API can be accessed using any OData-compatible application. This article assume that at least one entity has been exposed in the OData API (Managing OData Entities), and that at least one user has been given access to this resource.

Authentication

You can authorize users to access entities in the Connect API with authtokens. See Users for more information on how to create users and authentication tokens. Provide authtokens in HTTP authentication, shown below.

By default, access from all IP addresses is allowed. You can manage allowed IP addresses on the Endpoints page.

Use Auth Tokens in Basic Authentication

The user’s auth token should be used as the password when using Basic Authentication.

Use Auth Tokens in HTTP Header

Add the HTTP header x-cdata-authtoken with the desired auth token as part of the HTTP request.

GET https://myconnectserver/odata.rsc/my_entity

HTTP HEADERS
Accept: application/json
x-cdata-authtoken: MY_AUTH_TOKEN

Examples

Here are provided some examples using popular OData clients.

From cURL

One of the simplest ways to retrieve OData is using the cURL command line tool:

curl --header "x-cdata-authtoken: my_auth_token" "https://myconnectserver/odata.rsc/My_resource" 

cURL will return the OData response directly to the standard output.

From Postman

Postman is a testing utility tool that can easily connect to the Connect OData API. To connect to a resource exposed in this API, set the following settings:

  1. Set the HTTP operation to GET
  2. Set the request URL to https://myconnectserver/odata.rsc/my_resource
  3. In the Authorization tab, set the Auth type to Basic Auth
  4. Set the Username and password to the username and authentication token from the Users tab.
  5. Click Send to submit your request to Connect

Postman will display the OData results in the response section.

From JavaScript/JQuery

Javascript allows you to retrieve data from an OData source in a web-page. This example shows how to retrieve data from a Connect OData entity:

$.get("https://myconnectserver/odata.rsc/my_entity/", 
	{ "@authtoken": "MY_AUTH_TOKEN" }, 
	function(data) {
  $("#result").html(JSON.stringify(data));
});