eXo Platform provides APIs to create, update, delete and get information of an event. An event is represented as a JSON object as follows:
{
//Where the event is organized
"location": "",
//Priority of the event
"priority": "",
//Detailed description of the event
"description": "",
//Title of the event
"subject": "",
//Which calendar the event belongs to
"calendar": "",
//Status of the event, for example "busy"
"availability": "",
//All attachments of the event
"attachments": [ ],
//Recurrence id of the event
"recurrenceId": "",
//Id of the category which the event belongs to
"categoryId": "",
//Repetition information of the event
"repeat": {},
//Settings for reminding the event
"reminder": [],
//Privacy of the event
"privacy": "",
//Starting time of the event
"from": "",
//Link to the category the event belongs to
"categories": [],
//Ending time of the event
"to": "",
//Original event if any
"originalEvent": "",
//All participants of the event
"participants": [],
//Id of the event
id": "",
//Link to the event
"href": ""
}Getting information of an event
To retrieve information of an event, you need to send an Ajax GET request to /rest/private/v1/calendar/events/ by the following script:
function getEventById(){
$.ajax({
type: "GET",
url: "/rest/private/v1/calendar/events/"+event_id,
success: function (data, status, jqXHR) {
//process the returned data here
},
error: function (jqXHR, status) {
alert("Cannot retrieve data!");
}
});
}In which, event_id is Id of the event that you want to retrieve information. This request returns the information under a JSON object as indicated above.
Declare a simple event object such as:
var new_event={
"description": "Welcoming new comers in February",
"subject": "Welcome event",
"categoryId": "defaultEventCategoryIdMeeting",
"privacy": "private",
"from": "2015-07-30T04:30:00.000Z",
"to": "2015-07-30T05:30:00.000Z"
}Use an Ajax POST request to send this object to /rest/private/v1/calendar/calendars/{calendarId}/events 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 event will be added to the default calendar of the current logged-in user.
To update an event, you need to use this PUT request:
function updateEvent(){
$.ajax({
url: "/rest/private/v1/calendar/events/"+event_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("failed");
});
}In which, event_id is Id of the event that you want to update, and new_content is a JSON object containing new content of the event, for example:
var new_content={
"description": "Welcoming new comers in March",
"subject": "Monthly welcome event",
"categoryId": "defaultEventCategoryIdMeeting",
"privacy": "public",
"from": "2015-07-30T04:30:00.000Z",
"to": "2015-07-30T05:30:00.000Z"
}To delete an event, use the following DELETE request:
function deleteEvent(){
$.ajax({
url: "/rest/private/v1/calendar/events/"+event_id,
method: "DELETE"
}).done(function (data, status, xhr) {
//process the returned data here
}).fail(function (jqxhr, textStatus, error) {
alert("fail");
});
}In which, event_id is Id of the event that you want to delete.