0

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi < I have a few GET requests working in my SPFx app, but the guide here doesen't show you how to do a POST request with a payload which I can't get working.

Can anyone see where I am going wrong with the POST request:

Getting 500 error.

public updateProfile(nonDirectorTemp, directorTemp) {

    const spOpts: IHttpClientOptions = { 
        body: `{
        "PersonName": ${this.state?.currentUser?.name},
        "Declarations":  ${nonDirectorTemp.concat(directorTemp)
      }`
    };

    this.context.httpClient.post('https://f*********al-dev.azurewebsites.net/api/UpdateUserProfile', AadHttpClient.configurations.v1, spOpts)
    .then((res: HttpClientResponse): Promise<any> => {
      return res.json();
    })
    .then(() => {
      this.setState({ success: true }, () => setTimeout(() => {this.setState({ success: null });}, 1500));
    })
    .catch(error => this.setState({ error: error, isLoading: false }, () => setTimeout(() => {this.setState({ error: null });}, 1500))
   );

  }

1 Answer 1

1

That is how you do it:

this.httpClient.post('https://fu********al-dev.azurewebsites.net/api/UpdateUserProfile', AadHttpClient.configurations.v1, {
  body: JSON.stringify({
    "PersonName": this.state?.currentUser?.name,
    "Declarations": nonDirectorTemp.concat(directorTemp)
  })
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.