I am trying to use this.context.spHttpClient.post()
to update a calculated column formula in my SPFx WebPart.
I get a status code of 400 with the error message: "The parameter __metadata does not exist in method GetByTitle."
I have created the following function to perform this operation:
private _setCalculatedColumn(ListURL: string, ListTitle: string): void{
const body: ISPHttpClientOptions = {
body: `{'__metadata':{'type':'SP.FieldCalculated'},'Formula':'[my new formula]'}`
};
this.context.spHttpClient.post(
ListURL + `/_api/web/Lists/GetByTitle('`+ ListTitle +`')/Fields/GetByTitle('AutoTaskDueDate')`,
SPHttpClient.configurations.v1,
body)
.then((response: SPHttpClientResponse) => {
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);
});
});
}
I have found an example using Microsoft Flow but that is the closest I can find to updating a formula via a POST request.
I have changed around the body
string and get a similar error message.
Thanks