OData v4 REST

Our OData REST interface delivers and receives data in accordance with the Open Data Protocol.

We recommend studying the following tutorials before using our interface::

You can find the metadata of our interface here: https://api.beyond-sw.ch/$metadata

The interface is documented with the help of Swagger: https://api.beyond-sw.ch/help

Please note that our API returns a maximum of 100 data records. If more data records match the criteria, the response contains an @odata.nextLink.

Token

You need a bearer token for the protected functions of the REST interface. You can request this as follows:

HttpRequest  
Type POST
Url /Token

Headers
 
Content-Type   application/x-www.form-urlencoded

Body
 
grant_type password
username Benutzername für den API-Zugriff
password Passwort für den API-Zugriff

 

You use this token when calling with ‘Bearer ’ in front of it. For example:

Bearer 123456789

 

Expected return (example)

{
"access_token": "Beispiel",
"token_type": "bearer",
"expires_in": 3599,
"userName": "00000000-0000-0000-0000-000000000000",
".issued": "Sat, 04 Apr 2020 08:05:08 GMT",
".expires": "Sat, 04 Apr 2020 09:05:08 GMT"
}

API-Url

The url for API access is: https://api.beyond-sw.ch.

API user name and API password

To request a token, you need a user name and a password. You will receive this from support@beyond-sw.ch.

Example for php

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php 
$url = 'https://api.beyond-sw.ch/';
$userName = 'Benutzername für den API-Zugriff';
$key = 'Passwort für den API-Zugriff';
$token = requestToken();

$values = requestValues('kurse');
var_dump($values[0]['value']);

function requestToken()
{
global $url, $userName, $key;

$data =  array(
'grant_type'        => 'password',
'username'         => $userName,
'password'         => $key);

$handle = curl_init($url .'token');

curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($handle);
$jsonRaw = json_decode($response, true);

curl_close($handle);

return $jsonRaw['access_token'];
}

function requestValues($path, $returnField = null )
{
global $url, $token;

$header =  array(
'Content-Type: application/json',
'Authorization: Bearer ' . $token);

$handle = curl_init();

curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_TIMEOUT, 100);
curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
curl_setopt($handle, CURLOPT_URL, $url . $path);

$response = curl_exec($handle);

if ($returnField == null)
$jsonRaw = json_decode("[". $response . "]", true);
else
$jsonRaw = json_decode($response, true);

curl_close($handle);

if ($returnField == null)
return $jsonRaw;
else
return $jsonRaw[$returnField];
}
?> 
</body>
</html>
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.