A user is trying to use the JSON API via curl from Java to add a user to a group on Discourse, but receives a 400 Bad Request error. The issue occurs when executing curl from Java, though the same command works in the terminal. cookieman768 shares their Java code, which constructs the curl command with proper headers and JSON data. amotl suggests checking the command string and questioning the quoting and JSON formatting. After trying variations, including removing spaces in the JSON key and testing with usernames without special characters, the problem persists. amotl proposes removing the space in the JSON key, but cookieman768 concludes that the issue may lie in the Java execution environment and plans to use a library instead.
So, I’m using the JSON API to add a user to a group, it works as expected when I used the terminal but when I’m calling curl from Java I’m getting {"status":400,"error":"Bad Request"}
most probably, the arguments to curl (I assume you are shelling out from Java) are not forwarded correctly. This is often related to incorrect quoting.
If you share the corresponding Java code here, people might be able to guess what might be going wrong.
Thank you. I want to note that some lines end with \ and some not. Also, might the Umlaut have the chance to be the culprit here? Can you also test it with a username without an Umlaut?
Yeah, same issue - at this point, I’m most likely going to look into using a library for doing the request. I just have no idea why it’s being so difficult. Thank you for helping me troubleshoot.