Valmiit sovellukset on koottu omalle sivulleen.
Koodiesimerkkejä eri kielillä
PHP
<?php $url = 'https://opendata.tamk.fi/r1/reservation/search'; $apiKey='INSERT-KEY-HERE:'; $query= "{ \"startDate\":\"2015-09-22T09:00\", \"endDate\":\"2015-09-25T15:00\", \"room\":[\"C3-21\"] }"; $session = curl_init($url); // set up session curl_setopt($session, CURLOPT_USERPWD, $apiKey); // authentication curl_setopt($session, CURLOPT_POSTFIELDS, $query); // add query entries $response = curl_exec($session); // execute and get response curl_close($session); // close session var_dump($response); ?>
Lisää tarvittaessa seuraavat parametrit (viimeisen ’curl_setopt’-rivin jälkeen):
// ohita vahvistus, jos SSL-varmenne aiheuttaa ongelmia curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false); // palauta data merkkijonona curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using System.Net.Http.Headers; using System.Collections.Specialized; using System.Net; using Newtonsoft.Json; using System.Data; class Program { static void Main(string[] args) { String key = “INSERT-KEY-HERE"; fetch(key); } async static void fetch(String key) { using (var client = new HttpClient()) { try { StringContent content = new StringContent("{ 'codes': ['13TIKO']}", Encoding.UTF8, "application/json"); var response = await client.PostAsync("https://opendata.tamk.fi/r1/curriculum/search?apiKey=" + key, content); var responseString = await response.Content.ReadAsStringAsync(); dynamic stuff = JsonConvert.DeserializeObject(responseString); Console.Write(stuff.programmes[0].structureViews[0].relations[4].learningUnit.name); } catch (HttpRequestException e) { Console.Write(e); } } } }