HTTP put request error

AI-generated summary

Edwin_Mhoy_Silva is encountering an HTTP PUT request error when trying to update posts via the Discourse API from an Angular app running on localhost. While GET and POST requests work fine with CORS enabled in Discourse, PUT requests fail unless the Google CORS extension is active. The issue appears related to headers or server-side handling of PUT requests. RGJ identifies a relevant fix in a Discourse commit from September 17 (https://github.com/discourse/discourse/commit/f3214889dcf4391e397b6f81863182cf678482e5), which is not yet included in the stable release. Edwin_Mhoy_Silva confirms this matches their problem. codinghorror advises updating to the latest version of Discourse, which is considered stable, to resolve the issue. Edwin_Mhoy_Silva asks if the latest version is stable, to which codinghorror replies affirmatively with a :muscle: emoji, indicating the latest release is production-ready.

I’m having some issues with put request to my discourse from the api.
I can make, post and get request, but when I try to make a put request it doesn’t work.
My put request works, when I have the GOOGLE CORS extension on.

I am making api call from Angular localhost:4200.
I enable CORS inside the discourse management, which work fine with my other request, just not for my put request.

This is my error:

This is the header which I use


And this is my method, which does not work when I don’t use the google chrome extension

  addAboutCompetition(postId, dataForm) {

    const competitionForm = dataForm.value;
    const prize = competitionForm.competitionPrize;
    const description = competitionForm.competitionDescription;
    const endDate = competitionForm.competitionEndDate;
    console.log(endDate);
    const aboutText = '|type|normal|type| |endeDate|' + endDate + '|endeDate| |winner|false-/-null-/-none-/-avatar-/' +
      '-name-/-username|winner||price|' + prize + '-/p/-|price|' +
      '|text|<br><strong>UDFORDRINGEN</strong><br>' + description + '|text|';

    const data = new FormData();
    data.append('api_key', WLIApiKey);
    data.append('api_username', WLIUsername);
    data.append('post[raw]', aboutText);

    return this.http.put(url + '/posts/' + postId, data, {
      headers
    });
  }

I think it has something to do with my header maybe ?

This is fixed by this commit made on Sept 17:

https://github.com/discourse/discourse/commit/f3214889dcf4391e397b6f81863182cf678482e5

which is not available on Discourse stable yet.

Thanks for the @RGJ. This seems to be the problem I’m facing.

Simply update to latest and you’ll be good.

Is the latest stable yet?

Latest is always stable :muscle: