9.4.2.3.3. Tasks

eXo Platform provides APIs to create, update, delete and get information of a task. A task is represented as a JSON object as follows:

{
	//Name of the task
    "name": "",
	//Priority of the task
    "priority": "",
	//Status of the task
    "status": "",
	//Which calendar the task belongs to
    "calendar": "",
	//Detailed note of the task
    "note": "",
	//Settings for reminding the task
    "reminder": [],
	//Which users are assgined
	"delegation": [],
	//Starting time
	"from": "",
	//Id of the category which the task belongs to
	"categoryId": "",
	//Ending time
	"to": "",
	//All attachments of the task
	"attachments": [ ],
	//Link to the category which the task belongs to
	"categories": [],
	//Id of the task
    "id": "",
	//Link to the task
    "href": ""
}

Getting information of a task

To retrieve information of a task, you can use a GET request as below:

function getTaskById(){
					$.ajax({
						 type: "GET",
						 url: "/rest/private/v1/calendar/tasks/"+task_id,
						 success: function (data, status, jqXHR) {
							//process the returned data here
						 },
						 error: function (jqXHR, status) {
							 alert("Cannot retrieve data!");
						 }
					});
				}

In which task_id is Id of the task that you want to get information. This request returns the result under a JSON object as indicated above.

Creating a new task

Declare a simple task object such as:

var new_task={
						"name": "Documentation blog",
						"note": "Writing a documentation blog for the next deployment",
						"from": "2015-07-30T04:30:00.000Z",
						"to": "2015-07-30T05:30:00.000Z",
						"delegation": [current_user, "john"]
					}

where this task will be assigned to current_user and john. Use an Ajax POST request to send this object to /rest/private/v1/calendar/calendars/{calendarId}/tasks as the following script:

function createNewEvent(){
					$.ajax({
						url: "/rest/private/v1/calendar/calendars/"+current_user+"-defaultCalendarId"+"/events",
						contentType: "application/json",
						data: JSON.stringify(new_event),
						method: "POST"
						}).done(function (data, status, xhr) {
						   //process the returned data here
						}).fail(function (jqxhr, textStatus, error) {
							alert("failed");
					});
				}

In which, the new task will be added to the default calendar of the current logged-in user.

Updating a task

To update a task, you need to use this PUT request:

function updateTask(){
					$.ajax({
						url: "/rest/private/v1/calendar/tasks/"+task_id,
						contentType: "application/json",
						data: JSON.stringify(new_content),
						method: "PUT"
						}).done(function (data, status, xhr) {
						   //process the returned data here
						}).fail(function (jqxhr, textStatus, error) {
							alert("fail");
					});
				}

In which, task_id is Id of the task that you want to update and new_content is a JSON object containing new content of the task, for example:

var new_content={
						"name": "Writing documentation blog",
						"note": "Writing a documentation blog for the next deployment in June",
						"from": "2015-05-30T04:30:00.000Z",
						"to": "2015-05-30T05:30:00.000Z",
						"delegation": ["john"]
					}

Deleting a task

To delete a task, use the following DELETE request:

function deleteTask(){
					$.ajax({
						url: "/rest/private/v1/calendar/tasks/"+task_id,
						method: "DELETE"
						}).done(function (data, status, xhr) {
						   //process the returned data here
						}).fail(function (jqxhr, textStatus, error) {
							alert("fail");
					});
				}

In which, task_id is Id of the task that you want to delete.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus