Always get 400 when calling api/settings by curl

Must-share information (formatted with Markdown):

  • SonarQube 6.7
  • Programmatically setup web-hooks
  • I have tried by postman, it works

We like to run a bash script to setup web-hooks programmatically, but always get 400 code without any response body. the response is like:

POST /api/settings/set?key=sonar.webhooks.project&fieldValues={“name”:“Server_Stage”,“url”:“”}& HTTP/2

Authorization: Basic TOKEN
User-Agent: curl/7.54.0
Accept: /

  • Connection state changed (MAX_CONCURRENT_STREAMS updated)!

HTTP/2 400

server: nginx/1.14.1

date: Tue, 19 Mar 2019 15:14:55 GMT

Below are the curl requests:

curl -g -X POST -u ADMIN_API_TOKEN: -v ‘{“name”:“Server_Stage”,“url”:“”}

curl -g -X POST -u ADMIN_API_TOKEN: -v ‘{“name”:“Server_Stage”,“url”:“”}

We can successfully called other APIs like api/qualitygates/select or list but only this one not working. I guess there is something wrong with the query strings/parameters.
The wired thing is I tried to copy paste code from postman, it is not working either, but if I directly send message from postman it works.

Could you possibly help me to take a look whether something wrong my curl requests, many thanks in advance.

I have use alternative way which uses wget to make it work.

Thsnks @alexche1981 for letting us know that you’ve solved your issue, could you please explain how have you solved it ?
It could help someone else that would get into the same situation.

To be honest, I don’t really know what happened with curl, it is still not working, I just switch to wget to call that API which is working.

In case it helps, here’s a wget equivalent to curl that authenticates properly (no curl installed where I needed it):

$ curl -u ADMIN_API_TOKEN: [...]
$ wget --auth-no-challenge --http-user=ADMIN_API_TOKEN --http-password "" [...]

Note: The trailing : required for curl is replaced by the empty password for wget.

1 Like