Last active
August 29, 2015 14:26
-
-
Save HosseinNikpour/3df18b9a3dfa9883f1d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fetch = require('node-fetch'); | |
var btoa = require('btoa'); | |
function make_base_auth(user, password) { | |
var tok = user + ':' + password; | |
var hash = btoa(tok); | |
return "Basic " + hash; | |
} | |
function getData(auth, service_url) { | |
return fetch(service_url, { | |
method: 'get', | |
headers: { | |
'Authorization': auth, | |
'Accept': 'application/json; odata=verbose' | |
} | |
}) | |
.then(function (r) { | |
return r.text(); | |
}); | |
} | |
var USERNAME = 'nikpour'; | |
var PASSWORD = '123QWE!@#'; | |
var baseUrl='http://78.111.2.149:8030/nikpour/_api/Web'; | |
var auth = make_base_auth(USERNAME, PASSWORD); | |
var TaskListName = 'testTask'; | |
var TaskListURL=baseUrl+"/Lists(guid'E37AAEB7-AAAD-422A-9566-15F3DC07CC94')/items"; | |
function getAllTasks(auth) | |
{ | |
return getData(auth, TaskListURL) | |
.then(function (response){ | |
console.log(JSON.parse(response).d.results); | |
}) | |
.catch(function (e){throw new Error(e)}) | |
} | |
function getAllProjects(auth) | |
{ | |
var u = "/Lists(guid'DEBF6BEF-A3CF-4272-80CC-46287AE98E32')/items"; | |
return getData(auth, baseUrl + u) | |
.then(function (response){ | |
console.log(JSON.parse(response).d.results); | |
}) | |
.catch(function (e){throw new Error(e)}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment