© 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.

Web - RAP - Sample Application

RAP calls are lightweight and will service some applications effectively.  Please note that RAP calls are a mixture of purposes.  This guide refers solely to the 'Organisation' based APIs.

Sample Code is available from here.

Bearer Tokens

These are identical to One Roster, scopes and endpoints (live) are shown below.

  public static string SchoolOneRosterDataAccessToken(HttpClient httpClient,string clientId, string secret,  string orgId)
        {
            string scopes = "partner organisation onerosterapi rapapi"; // partner organisation rapapi onerosterapi
            AuthRequest arq = new AuthRequest();
            string rc = "";
            arq.Client_ID = clientId;
            arq.Secret = secret;
            arq.Organisation_ID = orgId; // Must have one
            arq.STS = "https://sts.sims.co.uk/connect/token";
            arq.Scopes = scopes;
            BearerToken bt = new BearerToken(arq, httpClient);
            rc = bt.Token;
            return rc;
        }

With the bearer token code being

 public BearerToken(AuthRequest arq, HttpClient httpClient)
        {

            string grant_type = "client_credentials";
            string client_id = arq.Client_ID; 
            string client_secret = arq.Secret;

            var form = new Dictionary<string, string>
                {
                    {"grant_type", grant_type},
                    {"client_id", client_id},
                    {"client_secret", client_secret},
                    { "scope", arq.Scopes },
                    { "acr_values","orgselected:"+arq.Organisation_ID }
                };

            var httpClientResponseTask = httpClient.PostAsync(arq.STS, new FormUrlEncodedContent(form));
            httpClientResponseTask.Wait();
            var result = httpClientResponseTask.Result;
            var responseStringTask = result.Content.ReadAsStringAsync();
            responseStringTask.Wait();
            //HttpCode = responseStringTask.Result.;
            string responseString = responseStringTask.Result;
            var jo2 = Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
            Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(jo2.ToString());
            Token = (string)jo.SelectToken("access_token");
        }

Calls are relatively straight forward and examples are provided for student, staff and parents - please note that at the time of writing, TIs will need to ask ESS to enable parent data on a school by school basis but we have requested that this is enabled by default or made a setting when defining a Tile in the store.

Data Returned

Staff
        public class RAPStaff
        {
            public string Id { get; set; }
            public string Title { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string EmailAddress { get; set; }
            public DateTime LastUpdated { get; set; }
            public string MainPhoneNumber { get; set; }
            public string Role { get; set; }
            public string OrganisationType { get; set; }
            public string ExternalId { get; set; }
        }
Student
 public class RAPStudent
        {
            public string Id { get; set; }
            public string Title { get; set; }
            public string FirstName { get; set; }
            public string MiddleName { get; set; }
            public string LastName { get; set; }
            public string EmailAddress { get; set; }
            public string DateOfBirth { get; set; }
            public string Gender { get; set; }
            public bool PupilPremiumStatus { get; set; }
            public YearGroup YearGroup { get; set; }
            public RegistrationGroup RegistrationGroup { get; set; }
            public DateTime LastUpdated { get; set; }
            public string StudentExtId { get; set; }
            public string UniquePupilNumber { get; set; }
            public string AdmissionNumber { get; set; }
            public string ParentEmailAddress { get; set; }
            public string MainPhoneNumber { get; set; }
        }
Parent
        public class RAPLearnerParent
        {
            public string Id { get; set; }
            public string Title { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string EmailAddress { get; set; }
            public DateTime LastUpdated { get; set; }
            public List<string> StudentMembers { get; set; }
            public string MainPhoneNumber { get; set; }
        }

Example Calls to populate

RAPAPIExamples.RAPStudents RAPstudents = new RAPAPIExamples.RAPStudents();
Dictionary<string, RAPAPIExamples.RAPStudents.RAPStudent> students = RAPstudents.GetValues(token, organisationId,  httpClient);
RAPAPIExamples.RAPStaffs RAPStaff = new RAPAPIExamples.RAPStaffs();
Dictionary<string, RAPAPIExamples.RAPStaffs.RAPStaff> staff = RAPStaff.GetValues(token, organisationId, httpClient);
RAPAPIExamples.RAPLearnerParents RAPparents = new RAPAPIExamples.RAPLearnerParents();  
Dictionary<string, RAPAPIExamples.RAPLearnerParents.RAPLearnerParent> parents = RAPparents.GetValues(token, organisationId, httpClient);

Expanding the call and class for staff as an example - see the sample code for the other 2...

        public Dictionary<string, RAPStaff> GetValues(string token, string organisationID, HttpClient httpClient)
        {
            // GET /ims/oneroster/v1p1/enrollments
            int OffSet = 0;
            Dictionary<string, RAPStaff> values = new Dictionary<string, RAPStaff>();
            string URL_Parents = null;
            if (PageSize != -1)
            {
                URL_Parents = SetURL(GetType, organisationID, OffSet, PageSize);
            }
            else
            {
                URL_Parents = SetURL(GetType, organisationID);
            }
            string resp = BaseClass.DoCall(URL_Parents, token, httpClient, "");
            try
            {
                List<RAPStaff> responses = new List<RAPStaff>();
                responses = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RAPStaff>>(resp);
                foreach (RAPStaff u in responses)
                {
                    values.Add(u.Id, u);
                }
                // Very likely > PageSize

                while (true && PageSize != -1)
                {
                    if (responses.Count != PageSize)
                    {  
                        break; // all done
                    }
                    OffSet += PageSize;
                    URL_Parents = SetURL(GetType, organisationID, OffSet, PageSize);
                    resp = BaseClass.DoCall(URL_Parents, token, httpClient, "");
                    responses = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RAPStaff>>(resp); 
                    foreach (RAPStaff u in responses)
                    {
                        values.Add(u.Id, u);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = "Error: " + resp;
            }
            return values;
        }

At the time of writing clarification was being sought as to whether RAP calls implement paging.  Pages sizes were set to -1 (assumes all data is returned in a single call) in the examples and in testing.