The Ed4Career Student Registration API allows for creating and deleting student registrations using a REST server. The sample code uses PHP but can be modified for other languages.
You will first need a user account setup with Ed4Career with API Access. Use these credentials when connecting to the API.
Below is a sample PHP script to create a Student Registration using our API:
IMPORTANT: for testing please use the following endpoint instead of the LIVE endpoint listed in the example: https://Ed4Career.ed4sandbox.com
<?php
function create_student_registration(){
// Authenticate Account
$request_url = 'https://ed4career.com/api/user/login'; // EndPoint URL for Authentication
$user_data = array(
'username' => 'USERNAME', // Your Ed4Career username
'password' => 'PASSWORD', // Your Ed4Career password
);
$user_data = http_build_query($user_data);
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $user_data); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE); // No return Header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($http_code != 200) {
// Error Handler
$http_message = curl_error($curl);
return $http_message ;
}
curl_close($curl);
$logged_user = json_decode($response);
$cookie_session = $logged_user->session_name . '=' . $logged_user->sessid;
// Create Student Registration
$request_url = 'https://ed4career.com/student_reg/create'; // EndPoint URL for Student Registrations
// Build the array to hold student and course registration info
// See the Address Glossary below for address field definitions
// NOTE that the address REQUIRED fields will vary depending on the country selected.
$reg['contact']['country'] = 'US';
$reg['contact']['administrative_area'] = 'FL';
$reg['contact']['sub_administrative_area'] = '';
$reg['contact']['locality'] = 'Orlando';
$reg['contact']['dependent_locality'] = '';
$reg['contact']['postal_code'] = '32801';
$reg['contact']['thoroughfare'] = '123 Main Street';
$reg['contact']['premise'] = 'Unit #2';
$reg['contact']['sub_premise'] = '';
$reg['contact']['first_name'] = 'John'; // REQUIRED FIELD
$reg['contact']['last_name'] = 'Smith'; // REQUIRED FIELD
$reg['contact']['phone'] = '555-555-5555'; // REQUIRED FIELD
$reg['registration']['student_email'] = 'test@email.com'; // REQUIRED
// The student's email address (must be unique).
$reg['registration']['program_name'] = 'Test Program'; // OPTIONAL
// Only needed for schools the require a 'program name' - leave blank if unsure.
$reg['registration']['start_date'] = '12/30/2017'; // OPTIONAL
// The student start date. Defaults to today if blank.
$reg['registration']['cost'] = '250.00'; // OPTIONAL
// This field is only needed if you need to submit a cost value. If unsure leave blank.
$reg['registration']['comments'] = 'This is a test comment';
// OPTIONAL | Add any comments for Ed4Career administrators to see. Not visible to students.
$reg['registration']['courses'][0] = 196; // REQUIRED
// Set this to the number unique identifier of the course (Node ID / NID). NID's can be obtained from your XML feed.
$reg['registration']['courses'][1] = 195; // OPTIONAL
// Continue adding additional courses as needed by incrementing the delta value (1,2,3,4, etc).
$reg['registration']['disable_email_notice'] = TRUE; // OPTIONAL
// Set this value to TRUE to disable sending an email notice to the site administrator. This is useful when testing.
$reg['registration']['account_id'] = 555; // OPTIONAL
// The user account ID (UID) of the school you're registering on behalf of. Leave blank to use your (API) login account.
$reg['registration']['classroom_pw'] = 'Password123'; // OPTIONAL
// Set a password for a new user when created in Moodle Classroom .
$reg['registration']['userset_name'] = 'YOUR CLASSROOM USERSET NAME'; // OPTIONAL
// Moodle userset can be specified. If empty userset will be determined from your user account.
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-CSRF-Token: ' . $logged_user->token)); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($reg)); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE); // Ask to not return Header
curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($http_code != 200) {
// Error Handler
$http_message = curl_error($curl);
return $http_message ;
}
//... success
}
?>
Upon successful creation the unique identifier of the Student Registration record will be returned. Example:
{"success":"5555"}
Once a new registration is created you can log into the Ed4Career.com website to view your "Previous Registrations" to be sure the API has created it correctly. Test registrations should be deleted once testing has completed.
IMPORTANT NOTE: Be sure to set the value for "disable_email_notice" to TRUE to avoid sending emails to the ED4 administrator while testing. For production this value should always be set to FALSE.
Address Glossary
country => Country (always required, 2 character ISO code)
name_line => Full name (default name entry)
first_name => First name
last_name => Last name
organisation_name => Company
administrative_area => State / Province / Region (ISO code when available)
sub_administrative_area => County / District (unused)
locality => City / Town
dependent_locality => Dependent locality (unused)
postal_code => Postal code / ZIP Code
thoroughfare => Street address
premise => Apartment, Suite, Box number, etc.
sub_premise => Sub premise (unused)
Moodle Password Requirements Password length - at least 8 Digits - at least 1 Lowercase letters - at least 1 Uppercase letters - at least 1 Non-alphanumeric characters - at least 1