Skip to content

Instantly share code, notes, and snippets.

@MudassarAli
Created November 6, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MudassarAli/59c375d95c2b8034d9dc9e54b37b840f to your computer and use it in GitHub Desktop.
Save MudassarAli/59c375d95c2b8034d9dc9e54b37b840f to your computer and use it in GitHub Desktop.
import * as sprequest from 'sp-request';
let spr = sprequest.create({
username: 'xxx',
password: 'xxx',
domain: 'xxx'
});
spr.post('https://xxx/sites/test/_api/contextinfo', {
body: {
},
headers: {
'Accept': 'application/json;odata=verbose',
'x-forms_based_auth_accepted': 'f'
}
})
.then((digest: any) => {
console.log("digestObj", digest)
console.log("digest", digest.body.d.GetContextWebInformation.FormDigestValue);
return spr.post('https://xxx/sites/test/_api/web/lists/GetByTitle(\'TestList\')', {
body: {
'__metadata': { 'type': 'SP.List' },
'Title': 'TestListNew'
},
headers: {
'Accept' :"application/json;odata=verbose",
'x-forms_based_auth_accepted': 'f',
'X-RequestDigest': digest.body.d.GetContextWebInformation.FormDigestValue,
'X-HTTP-Method': 'MERGE',
'IF-MATCH': '*'
}
});
})
.then(response => {
if (response.statusCode === 204) {
console.log('List title updated!');
}
}, err => {
if (err.statusCode === 404) {
console.log('List not found!');
} else {
console.log("Status code", err.statusCode);
console.log("Error", err.message);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment