© 2018 Capita Business Services Ltd. All rights reserved.

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.

Dex - Sample C# Calls

Whilst C# isn't every web coder's cup of tea, C# is a Capita standard and we also publish internal examples on the site.  Who knows, these may be useful to others.

One Roster - RAP API example code
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));
            var result = httpClientResponseTask.Result;
            var responseStringTask = result.Content.ReadAsStringAsync();
            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="";

 RAP Call Example

  private void ButtonRapStudent_Click(object sender, EventArgs e)

            string urlformat = @"https://simsid-partner-rapapi.azurewebsites.net/api/v1/Organisation/{0}/Students";
            string URL =string.Format(urlformat,textBoxOrgID.Text);

One Roster Call Example

 private void ExecuteGet(string URL)
                var request = new HttpRequestMessage()
                    RequestUri = new Uri(URL),
                    Method = HttpMethod.Get,
                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.hmrc.1.0+json"));
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", BearerToken);
                var httpClientResponseTask = httpClient.SendAsync(request);
                var result = httpClientResponseTask.Result;
                var responseStringTask = result.Content.ReadAsStringAsync();
                textBoxInfo.Text = responseStringTask.Result.ToString();
            catch (Exception ex)