Versions Compared

Key

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

Contents

Table of Contents
maxLevel2
printablefalse

There are two data points associated to an account when created via the EthosCE user interface, a user entity and a profile entity. Services creating accounts via web service must create both data points.

Creating a user with a profile

Creating a user via the web service can be accomplished with 2 requests to the system, with an extra request to verify the user does not already exist.

  1. Verify the user does not exist

...

  1. Send the user creation request

...

  1. Send a profile creation request,

...

  1. assigning it to the

...

  1. user via uid.

...

...

Verify

...

the

...

user exists

There are two ways to verify an account exists, checking by e-mail or SSO ID.

GET user.json?mail=newuser@dlc-solutions.com

...

GET authmap.json?authname=EXTERNAL_SSO ID

Create user account

POST user.json

This payload will create a user with the roles “course author” (105847459) and “reviewer” (175031666), by sending the corresponding role ids (rid) as an array of values.

Code Block
languagephp
{
	"name": "newuser_username",
	"mail": "newuser@dlc-solutions.com",
	"status": 1,
	"roles": [
	{
		"id": 105847459
	},
	{
		"id": 175031666
	}]
}

A successful user creation request returns the following:

Code Block
{"uri":"http://your-domain.com/user");
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($user));

  $json = curl_exec($curl);
  // An array detailing the new user entity is returned if successful
  $userInfo = json_decode($json);

// #3 Send a profile creation request, via POST, assigning it to the new user via uid.
  $profile = array(
    'user' => $userInfo->id, // The value sent back is a user entity, which identifies itself by entity id, which is also the Drupal uid
    'label' => 'Profile',
    'type' => 'profile',
    'field_first_name' => 'John',
    'field_middle_name' => 'Middle',
    'field_last_name' => 'Smith',
    'field_profile_location' => array(
      'street' => '1520 Locust Street',
      'additional' => 'Suite 1000',
      'city' => 'Philadelphia',
      'province' => 'PA',
      'postal_code' => '19102',
      'country' => 'us', // A two character country code
    ),
  );

  $curl = curl_init("http://your-domain.com/profile2");
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($profile));

  $json = curl_exec($curl);
  $response = json_decode($json);
}

...

/123","id":"123","resource":"user"}

Create profile demographics

POST profile2.json

Associating a profile to an account requires the user id (uid) to be assigned to the user field in the profile data. In the creation request above the uid value returned is 123.

Code Block
languagephp
{
	"user": 123,
	"label": "Profile",
	"type": "profile",
	"field_first_name": "John",
	"field_middle_name": "Middle",
	"field_last_name": "Smith",
	"field_profile_location":
	{
		"street": "123 S Broad Street",
		"additional": "Suite 2260",
		"city": "Philadelphia",
		"province": "PA",
		"postal_code": "19109",
		"country": "us"
	}
}


A successful profile creation request returns the following:

true
Code Block
linenumbers
{"uri":"http://your-domain.com/profile2/72","id":"72","resource":"profile2"}
Info

For an explanation of the information returned from the verification request, see Web Service Responses.

Updating a user role

User roles may be queried and updated via web services at the user endpoint. Only the changed fields need be included in a PUT request.

PUT user/123

Info

Sending or updating roles is a destructive process. Any PUT updates sent to the user.json endpoint must contain all role ids, both existing and new. The payload below, if sent to the user created on this page, will remove “course author” (105847459), add “report viewer” (92961712), and keep the “reviewer” role (175031666),

Code Block
languagephp
{
  "roles": [
	{
		"id": 92961712
	},
	{
		"id": 175031666
	},]
}

Related Pages

Creating an SSO User via Webservice

...