Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Remove references to session token

...

The course type may be updated by changing the type value , seen on line 15of the data array sent.


Internal Value
Coursecourse
Sessiongroup_event_series_event

...

Info
titleNOTE: When creating or updating an entity

An additional token is required for security, and must be passed in an X-CSRF-Token HTTP header. In the example below, the system is queried for this token on lines 2-8, and it is applied to the call on line 78.

For any call, you must specify the format being posted in a Content-Type HTTP header, either "application/json" or "text/xml"For any call, you must specify the format being posted in a Content-Type HTTP header, either "application/json" or "text/xml".

Creating a course

The PHP/Curl script below creates a course with the following details:

...

After creating the course (line 86) we record the new nid sent by the system (line 99), and use it to assign the 2 credit types.

Code Block
languagephp
titleCreating a course
linenumberstrue
<?php
$domain = 'your-domain.com';
$userpass = 'restws_webservice:restws_webservice';
$curl =
curl_init('http://' .Build $domaina . '/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); // Your web service user credentials goes here.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
// The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
print_r($token);
// Build a course to send, in JSON. 
$course = array(
  'title' => 'My Course',   // A single line textbox
  'type' => 'course',
  'field_course_summary' => array(   // A multi-line text area field
    'value' => 'A <b>summary</b> of the course',
    'format' => 'full_html'
  ),
  'author' => 1,   // It is best practice is to assign the Web Service user id as author
  'status' => 1,   //  Status (published): A single select checkbox. Either 1 or 0
  'field_course_datecourse to send, in JSON. 
$course = array(
  'title' => 'My Course',   // A single line textbox
  'type' => 'course',
  'field_course_summary' => array(   // A multi-line text area field
    'value' => 'A <b>summary</b> of the course',
    'format' => 'full_html'
  ),
  'author' => 1,   // It is best practice is to assign the Web Service user id as author
  'status' => 1,   //  Status (published): A single select checkbox. Either 1 or 0
  'field_course_date' => array(
    'value' => '2017-08-20T13:00:00',
    'value2' => '2018-08-20T21:00:00',
  ),
  'field_course_event_date' => array(
    'value' => '2018-08-20T13:00:00',
    'value2' => '2018-08-20T21:00:00',
  ),
  'sell_price' => 100.00,
  'model' => 'DLC_1234',
  'field_learning_objectives' => array(
    'value' => '2017-08-20T13:00:00<p>Objectives for learning.</p>',
    'value2format' => '2018-08-20T21:00:00',full_html'
  ),
  'field_coursehotel_event_datetravel' => array(
    'value' => '2018-08-20T13:00:00',
    'value2' => '2018-08-20T21:00:00',
  ),
  'sell_price' => 100.00,
  'model<p>Attendees will have a block of rooms available at <b>The Double Tree</b></p>',
    'format' => 'DLCfull_1234html'
  ),
  'field_learninghotel_objectivesinformation' => array(
    'value' => '<p>Objectives<p>Please call the front desk for learningrates.</p>',
    'format' => 'full_html'
  ),
  '"field_hotel_travel'link" => array(
    'value'"title" => '<p>Attendees will have a block of rooms available at <b>The Double Tree</b></p>',
    'format' => 'full_html'
  ),
  'field_hotel_information' "Venue Website",
    "url" => "doubletree3.hilton.com",
  ),
  'field_venue_phone' => array(
    'valuenumber' => '<p>Please call the front desk for rates.</p>2158931600',
    'formatcountry_code' => 'full_htmlus' // Link ),to list
  ),
  "field_hotelcourse_linklocation" => array(
    "titlename" => "VenueDouble Tree WebsitePhiladelphia",
    "urlstreet" => "doubletree3.hilton.com237 S Broad Street",
  ),   'field_venue_phone' "additional" => array("",
    'number'"city" => '2158931600'"Philadelphia",
    'country_code'"province" => 'us' // Link to list
  ),"PA",
    "fieldpostal_course_locationcode" => array("19107",
    "namecountry" => "Double Tree Philadelphiaus",
  ),
  "street"field_course_live" => "237 S Broad Street",
    "additional" => "",
    "city 1,   // The 'Live' checkbox, under Course settings must be checked for live events
  "field_course_category" => "Philadelphia",array(   // Course "province" => "PA",
    "postal_code" => "19107",
    "country" => "us",
  ),
  "field_course_live" => 1,   // The 'Live' checkbox, under Course settings must be checked for live events
  "field_course_categoryCategory is field containing a list of taxonomy terms. The id values entered here are the integer term ids
    array('id' => 50),
    array('id' => 60),
  ),
  "field_course_format" => array(
  // Course Category is field containing a list of taxonomy terms. The id values entered here are the integer term ids
 array('id' => 10),
    array('id' => 5020),
  ),
 array('id');
$json => 60),
  ),
  "field_course_format" => array(
    array('id' => 10),
    array('id' => 20),
  ),
);
$json = json_encode($course);
$curl = curl_init('http://' . $domain . '/node.json'json_encode($course);
$curl = curl_init('http://' . $domain . '/node.json');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPAUTHPOSTFIELDS, CURLAUTH_BASIC$json);
curl_setopt($curl, CURLOPT_USERPWD, $userpassHTTPHEADER, array("Content-Type: application/json"));
//Your credentials go here Send the course creation request
$http_return = curl_setoptexec($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
// Send the course creation request
$http_return = curl_exec($curl);
$response = json_decode($http_return);
print_r($response);
/*
 An example response, returned in JSON:
();
$response = json_decode($http_return);
print_r($response);
/*
 An example response, returned in JSON:
(
    [uri] => http://your-domain.com/node/408
    [id] => 408
    [uriresource] => http://your-domain.com/node/408
    [id] => 408
    [resource] => node
    [uuid] => f88adca4-8332-459c-873f-1bad3724b13e
)
*/
// Get the nid to send credit information
$nid = $response->id;
// Add Credit
$curl = curl_init('http://' . $domain . '/course_credit.json');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpass); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));

// Enable Attendance
$credit_attendance = array(
  'nid' => $nid,
  'active' => 1,
  'type' => 'attendance',
  "increments" => 0,
  "min" => 0,
  "max" => 1,
  "enable_variable_credit" => 0,
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($credit_attendance));
$http_return = curl_exec($curl);
$response = json_decode($http_return);
print_r($response);

// Enable AMA
$credit_ama = array(
  'nid' => $nid,
  'active' => 1,
  'type' => 'ama',
  "increments" => 0.25,
  "min" => 1.,
  "max" => 5.5,
  "enable_variable_credit" => 1,
);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($credit_ama));
$http_return = curl_exec($curl);
$response = json_decode($http_return);
print_r($response);

...

Code Block
languagephp
titleUpdating a course's title
<?php
// $curlBuild a = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
print "Received token: " . $token . "\n";

// Token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
// Build a course
// The fields and allowed values are available on the full documentation site.
$course = array(
  'title' => 'My Updated Course',
);
$json = json_encode($course);
$curl = curl_init('http://your-domain.com/node/408');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$response = curl_exec($curl);
print $response;

Updating a course's external ID

After creating a course via web service, clients may need to update the E field, with a value associated to the external system. This update call is different than the title, detailed above.  The title field is attached to the node entity, however the External course ID field is attached to the course entity, a separate collection of data. It is used for primarily for internal purposes, and is seldom changed manually. However, in this case of a course created externally via web service, there may be a need to associate the new course with an external system ID. 

To update the course created in the previous section, we take the nid returned, above example is 408, and send a PUT call, via the course endpoint, to updated the External course ID fieldThe internal name of the field is external_id.

Info
iconfalse
titleWarning
It is not recommended to update any other fields found in the course endpoint, except external_id, as they are programatically created/updated when editing a course via the UI.
Code Block
languagephp
titleUpdating a course's external ID
<?php

$curl = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
print "Received token: " . $token . "\n";

// Token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
course
// The fields and allowed values are available on the full documentation site.
$course = array(
  'title' => 'My Updated Course',
);
$json = json_encode($course);
$curl = curl_init('http://your-domain.com/node/408');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$response = curl_exec($curl);
print $response;

Updating a course's external ID

After creating a course via web service, clients may need to update the E field, with a value associated to the external system. This update call is different than the title, detailed above.  The title field is attached to the node entity, however the External course ID field is attached to the course entity, a separate collection of data. It is used for primarily for internal purposes, and is seldom changed manually. However, in this case of a course created externally via web service, there may be a need to associate the new course with an external system ID. 

To update the course created in the previous section, we take the nid returned, above example is 408, and send a PUT call, via the course endpoint, to updated the External course ID fieldThe internal name of the field is external_id.


Info
iconfalse
titleWarning
It is not recommended to update any other fields found in the course endpoint, except external_id, as they are programatically created/updated when editing a course via the UI.


Code Block
languagephp
titleUpdating a course's external ID
<?php
// Build a course
// The fields and allowed values are available on the full documentation site.
$course = array(
  'external_id' => 'ethosce_ext_id_12345',
);
$json = json_encode($course);
$curl = curl_init('http://your-domain.com/course/408');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials go here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$response = curl_exec($curl);
print $response;

...