Last active
September 19, 2022 15:48
-
-
Save vman/9f706f9779308f068120ffe212306456 to your computer and use it in GitHub Desktop.
Making a POST request to SharePoint from an SPFx webpart
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
private _makePOSTRequest(): void { | |
const spOpts: ISPHttpClientOptions = { | |
body: `{ Title: 'Developer Workbench', BaseTemplate: 100 }` | |
}; | |
this.context.spHttpClient.post(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists`, SPHttpClient.configurations.v1, spOpts) | |
.then((response: SPHttpClientResponse) => { | |
// Access properties of the response object. | |
console.log(`Status code: ${response.status}`); | |
console.log(`Status text: ${response.statusText}`); | |
//response.json() returns a promise so you get access to the json in the resolve callback. | |
response.json().then((responseJSON: JSON) => { | |
console.log(responseJSON); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment