Created
November 6, 2018 12:38
-
-
Save MudassarAli/59c375d95c2b8034d9dc9e54b37b840f to your computer and use it in GitHub Desktop.
This file contains 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
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