A bit of backstory: In August of 2018, I was tasked with creating a plugin for Discourse to add a few custom_fields to the User model. A bit of code hackery later, and a working plugin was created, as well as a ruby script to make a PUT request to update the custom fields via the API. Then I was reassigned to work on other things.
Fast forward to the present, and I am tasked with ensuring the plugin and associated code will work properly. The first thing I did was access the server running dockerized discourse, and update the server and discourse. The app was then rebuilt.
I then ran the test script and it failed to update the custom fields but it did return a 200 status. Checking the production log of discourse shows that the parameters are being received. however the log also states “Can’t verify CSRF token authenticity.”
Any advice to help debug the issue would be greatly appreciated
Are you using a valid API key in the request? CSRF protection is in place for all requests (except GET), so you will need to use an API key to make the the PUT request succeed.
assuming “key” is defined in the script
the end point is: https://HOSTNAME/users/jezra?api_key=${key}&api_username=system
and I’m attempting to use curl at the moment
Yes, the CSRF error would suggest a bad API key. The other issue you may be running into is that we added some protection for user custom fields back in September 2018. If you want to be able to edit them from the API, you now need to add something like