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.
There is an example:
http://msdn.microsoft.com/en-us/library/office/dn499819(v=office.15).aspx
executor.executeAsync({
url: "<app web url>/_api/SP.AppContextSite(#target)/web/getchanges?#target='<host web url>'",
method: "POST",
body: "{ 'query': { '__metadata': { 'type': 'SP.ChangeQuery' }, 'Web': true, 'Update': true } }",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
success: successHandler,
error: errorHandler
});
Please refer https://msdn.microsoft.com/en-us/library/office/dn499819.aspx.
Following code is working for me.
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getchanges",
type: "POST",
data: "{ 'query': { '__metadata': { 'type': 'SP.ChangeQuery' },'Web': true, 'Update': true, 'Add': true } }",
headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose",'X-RequestDigest':$('#__REQUESTDIGEST').val() },
success: successHandler,
error: errorHandler
});
function successHandler(data, textStatus, jqXHR ){
alert("successHandler " + "textstatus:" +textStatus + "data: " + data);
}
function errorHandler(xhr, ajaxOptions, thrownError) {
alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);
}
Related
I have an app that connects doctors with patients. When I use the API to create a meeting for the doctor, I get the following error:
{ code: 200, message: 'Invalid api key or secret.' }
var defer = Q.defer();
var op = {
method: "POST",
uri: "https://api.zoom.us/v2/users/" + options.email + "/meetings",
body: {
topic: "test.com 1-1 session",
type: 2,
start_time: new Date(options.startDate),
duration: 40,
settings: {
host_video: "true",
participant_video: "true"
}
},
headers: {
'content-type': 'application/json',
authorization: `Bearer ${options.refreshToken}`
},
json: true //Parse the JSON string in the response
};
request.post(op, (error, response, body) => {
if (error) {
defer.reject(error);
}
defer.resolve(body);
});
return defer.promise;
Can someone please help?
im trying to ensure some user and get in post 500 (Internal Server Error).
function ensureUser(webUrl,loginName)
{
var data = { 'logonName': loginName };
return $.ajax({
url: webUrl + "/_api/web/siteusers",
type: "POST",
data: JSON.stringify(data),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose"
}
});
}
var loginName = 'i:0#.w|nsm\eilonte'
ensureUser(_spPageContextInfo.webAbsoluteUrl,loginName)
.done(function(data)
{
console.log('success');
})
.fail(function(error){
console.log(error);
});
this is the error:
jquery-1.12.4.js:10254 POST http://blabla/_api/web/ensureuser 500 (Internal Server Error)
send # jquery-1.12.4.js:10254
ajax # jquery-1.12.4.js:9738
ensureUser # VM2574:4
(anonymous) # VM2574:17
cant identify what is the problem.
Try using below code for ensure user.
function ensureUser(webUrl,loginName)
{
var payload = { 'logonName': loginName };
return $.ajax({
url: webUrl + "/_api/web/ensureuser",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(payload),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"accept": "application/json;odata=verbose"
}
});
}
var loginName = 'emailid'
ensureUser(_spPageContextInfo.webAbsoluteUrl,loginName)
.done(function(data)
{
console.log('User has been added');
})
.fail(function(error){
console.log('An error occured while adding user');
});
You are not sending the username as JSON. Change the "Content-Type" header to:
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
Also I think the API endpoint is
_api/web/ensureuser
DigiSigner is working fine if I call it from the postman, but it is giving error Bad Request if I call it with axios form nodejs application.
Here is my code sample.
const digi_signer_url = "https://api.digisigner.com/v1/documents";
const digi_signer_options = {
method: 'POST',
headers: { "Content-Type": "multipart/form-data", 'Authorization': `Basic ${process.env.DIGI_SIGNER_KEY}` },
data: {file: file},
url: digi_signer_url,
}
const r = axios(digi_signer_options)
Here is the solution.
const opts = {
method: 'POST',
url: 'https://api.digisigner.com/v1/documents',
headers:
{
'cache-control': 'no-cache',
authorization: `Basic ${process.env.DIGI_SIGNER_KEY}`,
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
},
formData:
{
file:
{
value: fs.createReadStream(path.join(__dirname, '../../templates/sample-po.pdf')),
options: { filename: 'sample-po.pdf', contentType: null }
}
}
};
request(opts, function (error, response, body) {
if (error) throw new Error(error);
if (body) {
const document = JSON.parse(body);
const {document_id} = document;
const send_to_signature = {
method: 'POST',
url: 'https://api.digisigner.com/v1/signature_requests',
headers:
{
'cache-control': 'no-cache',
'content-type': 'application/json',
authorization: `Basic ${process.env.DIGI_SIGNER_KEY}`
},
body:
{
documents:
[{
document_id: document_id,
subject: subject,
message: content,
signers:
[{
email: to_email,
fields: [{ page: 0, rectangle: [0, 0, 200, 100], type: 'SIGNATURE' }]
}]
}]
},
json: true
};
request(send_to_signature, function (error, response, result) {
if (error) throw new Error(error);
console.log(result)
});
}
});
My problem was to upload the file from local directory to Azure Data Lake Store using Typescript only. I then found very useful REST API solution, I tested the REST API to perform all the required operations through postman and they worked fine, I then moved to Typescript to make these calls from typescript. Here is link to that: https://learn.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-rest-api
To make REST CALLS through Typescript I'm using request-promise package, that I installed using npm install request-promise command. The documentation of this package is provided in this link:- https://github.com/request/request
But i'm able to perform all operations of the REST API i.e; Service-to-Service authentication, Creating Folder, Listing Folders, Rename File, Read File and so on. But i am not able to perform two operations/REST CALLS i.e; Upload File and Delete File, every time I make this call it gives Run Time Exception and error code 501 saying that this operation has not been implemented though i have tested these operations through Post Man and they work fine that way.
Is there any Access problem or what?
Here is the code of Typescript:
var fs = require('fs');
var request = require('request-promise');
var accessToken;
getAccessToken();
setTimeout(listFolders, 5000);
setTimeout(renameFile, 5000);
setTimeout(uploadData, 5000);
setTimeout(readData, 5000);
function getAccessToken() {
request(
{
method: 'post',
url: 'https://login.microsoftonline.com/067e9632-ea4c-4ed9-9e6d-
e294956e284b/oauth2/token',
form: {
grant_type: 'client_credentials',
resource: 'https://management.core.windows.net/',
client_id: 'dc9a4034-b03f-4974-9760-99541137a31c',
client_secret: 'mJ1Eba+sz0hXQko7gBN3D5WPDVLySCHXg4Mg5F4Ru4s='
},
json: true,
}, function (error, response, body) {
//Print the Response
accessToken = body.access_token;
console.log(accessToken);
});
}
function uploadData() {
fs.createReadStream('E:/accessToken.txt')
.pipe(request({
method: 'post',
url:
'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalytics/abc.txt?
op=CREATE',
json: true,
headers: {
"Authorization": "Bearer " + accessToken,
}
},
function (error, response, body) {
console.log(response.status);
}
));
}
function readData() {
request(
{
method: 'GET',
url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalyti
cs/readFile1.txt?op=OPEN'
headers: {
"Authorization": "Bearer " + accessToken,
},
json: true,
}, function (error, response, body) {
//Print the Response
console.log("\n\nData = "+body);
//console.log(response);
}
);
}
function listFolders() {
request(
{
method: 'GET',
url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
iModelAnalytics?op=LISTSTATUS',
headers: {
"Authorization": "Bearer " + accessToken,
},
json: true,
}, function (error, response, body) {
//Print the Response
console.log("************List Folders*****************\n ");
console.log(body);
}
);
}
function deleteFile() {
request(
{
method: 'PUT',
url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
iModelAnalytics/readFile.txt?op=DELETE',
headers: {
"Authorization": "Bearer " + accessToken,
},
json: true,
}, function (error, response, body) {
//Print the Response
console.log("***************Delete File*****************\n ");
console.log(body);
console.log('Response= \n');
console.log(response);
}
);
}
function renameFile() {
request(
{
method: 'PUT',
url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
iModelAnalytics/readFile1.txt?
op=RENAME&destination=/iModelAnalytics/readFile2.txt',
headers: {
"Authorization": "Bearer " + accessToken,
},
json: true,
}, function (error, response, body) {
//Print the Response
console.log("*************************Delete File*****************\n
");
console.log(body);
console.log('Response= \n');
console.log(response);
}
);
}
This is the error that I get:
Please share any thoughts regarding this.
Thanks a lot in advance.
PUT should be used to upload data whereas DELETE should be used to delete a file.
Append this &write=true to the query string when uploading data via pipe.
Try to change the code to:
function uploadData() {
fs.createReadStream('E:/accessToken.txt').pipe(request({
method: 'put',
url:'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalytics/abc.txt?op=CREATE&write=true',
json: true,
headers: {
"Authorization": "Bearer " + accessToken,
}
}, function (error, response, body) {
console.log(response.status);
}));
}
function deleteFile() {
request({
method: 'delete',
url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalytics/readFile.txt?op=DELETE',
headers: {
"Authorization": "Bearer " + accessToken,
},
json: true
}, function (error, response, body) {
//Print the Response
console.log("***************Delete File*****************\n ");
console.log(body);
console.log('Response= \n');
console.log(response);
});
}
I am trying to send some data to another server. This includes a file as well. Here is how I am doing it:
var fs = require("fs");
var request8 = require("request");
var _value = fs.createReadStream(_completefilePath);//File that needs to be sent.
var options = {
method: 'POST',
url: _uploadURL,
headers: {
'content-type': 'multipart/form-data'
},
formData: {
fileName: {
value: _value,
options: { filename: _fileName, contentType: null }
},
data: JSON.stringify(_data)//_data is a JSON object
}
};
request8(options, function (error, response, body) {
if (!error && response.statusCode == 200)
return 1
else
return 0;
});
I have tried many times but the error I get is "ECONNRESET". I have no idea what is wrong with the request above? Is it not properly formed or is there any issue on third party server?
Basically I am trying to upload a file to Eventbrite server. The code in Python is given here under step 2 and that's what I am trying to convert in NodeJS.
[Update 1]: When I changed "formData" to "form" I got statusCode 412(precondition failed).
[Update 2]: Changing the code to below gives "Bad Request" error.
var options = {
method: 'POST',
url: _uploadURL,
headers: {
'content-type': 'multipart/form-data',
'Authorization': 'Bearer ' + _token
},
formData: JSON.stringify({
fileName: {
value: _value,
options: { filename: _fileName, contentType: null }
},
data: _data
})
};