Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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