Skip to content

Instantly share code, notes, and snippets.

@vman
Created April 28, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vman/0bbf85b94715895d8ff3cd19ffbfecf0 to your computer and use it in GitHub Desktop.
Save vman/0bbf85b94715895d8ff3cd19ffbfecf0 to your computer and use it in GitHub Desktop.
private async createListItem() {
try {
const spOpts: ISPHttpClientOptions = {
body: `{ Title: 'My New Item' }`
};
const response = await this.context.spHttpClient.post(`https://tenant.sharepoint.com/sites/anothersitecollection/_api/web/lists/GetByTitle('test')/items`, SPHttpClient.configurations.v1, spOpts);
if (!response.ok) {
const responseText = await response.text();
throw new Error(responseText);
};
const responseJSON = await response.json();
console.log(responseJSON);
} catch (error) {
console.log(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment