Adding a user or course node to a group via web services

In EthosCE, when a course node or user is added to a group, they are both considered "members", stored in the same way, with slight variations on specific attributes. Both are available via web services to be created, updated, or deleted via the og_membership endpoint.

The fields that will change are: the attached "entity" (either a user or a course node) and "field_name". The "field_name" field accepts two valid options: og_user_node (when adding a user), or og_group_ref  (when adding a node).

Adding a user to a group

There are two methods to enrolling a user in a group. You may enroll them in a course that exists within the group, or manually add them as a member to the group itself. When enrolling a learner in a course which exists in a group, the learner is automatically added as a Member to the parent group. This includes enrollments created via web services. If enrolled in this manner, no futher action is needed to ensure the learner is enrolled in both the course and it's parent.

However, to manually add a user to the group, the following data payload must be sent to the og_membership endpoint.

Example Payload
{ "group": { "id":5401, "resource":"node" }, "entity": { "id":12, // The user uid "resource":"user" }, "type":"og_membership_type_default", "field_name":"og_user_node", "state":1, "created": 1556290324, "language": "en" }

The preceding code will add the user with UID 12 to the group with node ID 5401.

Comments are not supported in JSON. Be sure to remove // The user uid if copying and pasting the preceding code.

Adding a course

Adding a course to the group also utilizes the og_membership endpoint, with the following updates to the data: The "entity" resource type will be updated to specify a node is being sent, with the nid in the 'id' value, and the field_name value will update to 'og_group_ref'.

Adding a course to a group
{ "group": { "id":5401, "resource":"node" }, "entity": { "id":50, // The course nid "resource":"node" }, "type":"og_membership_type_default", "field_name":"og_group_ref", "state":1, "created": 1556290324, "language": "en" }

The preceding code will place the course with node ID 50 in the group with node ID 5401.

Additional notes

Consistent Values

The following fields will not change between either users or courses added to a group

  • "type" : "og_membership_type_default",

  • "state" : 1,

  • "language" : "en"