I am try to convert this old school example. It was drop 3, now I need to convert it to SPFx RC version;
private createItem(): void {
this.getListItemEntityTypeName()
.then((listItemEntityTypeName: string): Promise<Response> => {
const body: string = JSON.stringify({
'__metadata': {
'type': listItemEntityTypeName
},
'Title': `Item ${new Date()}`
});
return this.props.httpClient.post(`${this.props.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items`, {
headers: {
'Accept': 'application/json;odata=nometadata',
'Content-type': 'application/json;odata=verbose',
'odata-version': ''
},
body: body
})
only diff is shape of post. changed to;
private createItem(): void {
this.getListItemEntityTypeName()
.then((listItemEntityTypeName: string): Promise<Response> => {
return this.props.httpClient.post(`${this.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items`,
SPHttpClient.configurations.v1,
"https://mydomain.sharepoint.com/sites/test14jan"
})
}
method simple adding an item to list in domain. myweb part running in server(https://mydomain.sharepoint.com/_layouts/15/workbench.aspx)
each time I refresh the page this error seems in console(before call any method)
"403 forbidden" can you help me to solve this please? I am pretty sure this cause my problem because I am able to get items from list via this get method;
this.props.httpClient.get(`${this.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items?$select=Title,Id`,
SPHttpClient.configurations.v1)
so something wrong with post. using oldschool header object not works with spfx RC.0 as you know