The events for a current month could be retrieved via the following CAML query:
<Where>
<DateRangesOverlap>
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<Value Type='DateTime'>
<Month />
</Value>
</DateRangesOverlap>
</Where>
For that matter GetItems
method could be utilized as demonstrated below:
var query = `
<Where>
<DateRangesOverlap>
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<Value Type='DateTime'>
<Month />
</Value>
</DateRangesOverlap>
</Where>`
getListItems(_spPageContextInfo.webAbsoluteUrl,'TeamCalendar',query)
.done(function(data){
var items = data.d.results;
for(var i = 0; i < items.length;i++) {
console.log(items[i].Title);
}
})
.fail(function(error){
console.log(JSON.stringify(error));
});
where
function getListItems(webUrl,listTitle, queryText)
{
var viewXml = '<View><Query>' + queryText + '</Query></View>';
var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
var queryPayload = {
'query' : {
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml' : viewXml
}
};
return $.ajax({
url: url,
method: "POST",
data: JSON.stringify(queryPayload),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
}
});
}
But there is one limitation with this approach, neither REST nor CSOM/JSOM APIs do not support expanding for recurring events (it means only a single event item will be returned for a recurring event). Refer those requests for a more details:
For that scenario legacy SharePoint Web Services comes to the rescue, in particular Lists Web Service.
The following example demonstrates how to retrieve events for a current month and expand recurring events (SPServices library is utilized here):
$().SPServices({
operation: "GetListItems",
async: false,
listName: "TeamCal",
CAMLViewFields: "<ViewFields>" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' />" +
"<FieldRef Name='Location' />" +
"<FieldRef Name='Description' />" +
"<FieldRef Name='fRecurrence' />" +
"<FieldRef Name='RecurrenceData' />" +
"<FieldRef Name='fAllDayEvent' />" +
"</ViewFields>",
CAMLQuery: "<Query>" +
"<Where>" +
"<DateRangesOverlap>" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' />" +
"<FieldRef Name='RecurrenceID' />" +
"<Value Type='DateTime'>" +
"<Month />" +
"</Value>" +
"</DateRangesOverlap>" +
"</Where>" +
"<OrderBy>" +
"<FieldRef Name='EventDate' />" +
"</OrderBy>" +
"</Query>",
CAMLQueryOptions: "<QueryOptions>" +
"<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>" +
"<ExpandRecurrence>TRUE</ExpandRecurrence>" +
"</QueryOptions>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var $node = $(this);
var eventTitle = $node.attr("ows_Title");
console.log(eventTitle);
});
}
})