I'm trying to get an individual change event using;
GET * https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges('query')/item
Reference
http://msdn.microsoft.com/en-us/data/jj246759(v=office.12).aspx
And
http://msdn.microsoft.com/en-us/library/office/jj246759(v=office.15).aspx
I'm unable to get it working, and I can't find any example of this call.
I'm trying something like;
GET
https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges('Add=true,Item=true')/item
https://{sitecollection}/{personal/user_name_domain_onmicrosoft_com}/_api/web/getchanges(query='Add=true,Item=true')/item
but no luck.
FYI:: I'm not trying to get changelogs with this call. I'm trying to get an individual change item. But since the syntax is like that I put a random query in the those braces. The /getchanges(which is a POST call) works fine.
Any help on this?
There are at least two options how to construct request for a ChangeCollection
endpoint:
Option 1
Post ChangeQuery
via request body
function getChanges(webUrl,queryOptions,success,failure)
{
var changeQueryPayload = {
'query':{
'__metadata': { 'type': 'SP.ChangeQuery' },
}
};
for(var key in queryOptions) {
changeQueryPayload['query'][key] = queryOptions[key];
}
$.ajax({
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
data: JSON.stringify(changeQueryPayload),
url: webUrl + '/_api/web/getchanges',
success: success,
failure: failure
});
}
Option 2
Pass ChangeQuery
expression via query string:
function getChanges(webUrl,queryOptions, success,failure)
{
$.ajax({
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
url: webUrl + '/_api/web/getchanges(@qry)?@qry=' + JSON.stringify(queryOptions) + ,
success: success,
failure: failure
});
}
Example
Retrieve updates for a web:
var queryOptions = {"Update":true,"Web":true};
getChanges(_spPageContextInfo.webAbsoluteUrl,queryOptions,
function(result){
var changes = result.d.results;
//print info
console.log('Found ' + changes.length + ' items');
},
function(error){
console.log(JSON.stringify(error));
});
Regarding requesting a specific change item, it could be retrieved from a results returned from REST service.