Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Regent API Code Examples

Further examples showing how to interact with Student, Award and Documents. This is meant as an addendum to the main document found here: Regent Award .Net API User Guide

(info) Note: The examples below make use of the generic 'Student Portal' username and do not use a ClientId and Token. This is because the code below is example only. In practice the SecurityToken object should use a ClientId and Token as shown in the Regent Award .Net API User Guide. These two data attributes are provided by Regent after the client request to provision the web service end point is received


Code Block
languagec#
titleGet Student External Id by Student Id
linenumberstrue
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using YourServiceReferenceHere;


public SecurityToken GetAuth()
{
    SecurityToken securityToken = new SecurityToken()
    {
        Username = "Student Portal",
        UserId = -2,
        DashboardAdmin = true
    };

    return securityToken;
}

public async Task<long> GetStudentIdAsync()
{
    long studentid = -1;


    string externalId1 = "63650";
    GetStudentsRequest getStudentsRequest = new GetStudentsRequest();
    getStudentsRequest.SecurityToken = GetAuth();
    RegentEnterpriseServiceClient client = new RegentEnterpriseServiceClient();
    client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://regentremwsqa9.regenteducation.local/RegentEnterpriseWebService.svc");


    // this method is special in that you can build a dynamic set of filters. Here we want to find student internal Id
    getStudentsRequest.filter = new Filter
    {
        Filters = new List<Filter>
        {
            new Filter {Field = "externalId1", Operator = "eq", Value = externalId1}
        }.ToArray()
    };
    // here you cann add the additional conditions as sorting and the number of returning rows
    getStudentsRequest.sortColumn = null;
    getStudentsRequest.sortExpression = null;
    getStudentsRequest.startRowIndex = 1; // start and end row indexes are required to provide
    getStudentsRequest.endRowIndex = 1;
    
    getStudentsResponse = await client.getStudentBasicInfoListAsync(getStudentsRequest);

    if (!getStudentsResponse.Success)
        throw new ApplicationException(string.Format("Error calling {0}:{1}", "getStudentBasicInfoListAsync", getStudentsResponse.Message));

    // expect you'll get 1 and only 1 record. Adjust for your needs.
    if (getStudentsResponse.Records.Length != 1)
    {
        throw new ApplicationException(string.Format("Expected 1 student record but found {0} records", 0));
    }

    studentid = getStudentsResponse.Records[0].Id;
    return studentid;
}

...