Capita Education Software Solutions is a trading name of
Capita Business Services Ltd. Our Registered office is 30
Berners Street, London, W1T 3LR and our registered number
is 02299747. Further information about Capita plc can be
found in our legal statement.
Reference this page from a Product sub category page to inherit assets
Dex - Sample C# Calls
Whilst C# isn't every web coder's cup of tea, C# is an ESS standard and we also publish internal examples on the site. Who knows, these may be useful to others.
Exemplar code overview
The first task is to register for Technical Integrator Service and ask for a 'One Roster / RAP API Sandbox'. There are two forms of these, the fremium version which is basic data and enhanced versions which will be linked to data sets of the TI's choice (We expect the enhanced service to be available from Q4 2019.)
This provides the:
Organisation ID
Client ID
Secret
The scope is: onerosterapi onerosterapi-write organisation partner rapapi
The partner STS is: https://simsid-partner-stsserver.azurewebsites.net/connect/token
The code is in 2 parts:
Get the Bearer Token
Make the API call.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http;
using System.Web.Script.Serialization;
using System.Net.Http.Headers;
using System.Web;
Access Token
private string GetBearerToken()
{
string grant_type = "client_credentials";
string client_id = textBoxClientID.Text; ;
string client_secret = textBoxSecret.Text;
var form = new Dictionary<string, string>
{
{"grant_type", grant_type},
{"client_id", client_id},
{"client_secret", client_secret},
{ "scope", textBoxScope.Text },
{ "acr_values","orgselected:"+textBoxOrgID.Text }
};
var httpClientResponseTask = httpClient.PostAsync(textBoxSTS.Text, new FormUrlEncodedContent(form));
httpClientResponseTask.Wait();
var result = httpClientResponseTask.Result;
var responseStringTask = result.Content.ReadAsStringAsync();
responseStringTask.Wait();
string responseString = responseStringTask.Result;
var JSONObj = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(responseString);
string tok = JSONObj["access_token"];
//
//var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
//Token tok = JsonConvert.DeserializeObject<Token>(jsonContent);
return tok;
}
public string BearerToken="";