Handle special characters in URL using the SQ Web API


my question is how to handle special characters in URL using the SQ Web API?

My concrete issue is that I like to use the Web API to set the parameter for java:S1451 (Track lack of copyright and license headers). The problem is that one of the values is a regular expression with special characters. How do I have to encode them in the URL?

POST api/qualityprofiles/activate_rule
{ "rule":"java:S1451", "isRegularExpression":true, "headerFormat":"//\s*<copyright> XXX" }

POST api/qualityprofiles/activate_rule?rule=java:S1451&params=???

  • Which characters must be percent-encoded?
  • Is blank %20 or is also + supported?

Thanks in advance.


Hi, you don’t need to use query param. You can actually use form param, directly in the form body of the request. Like this:

curl --request POST -F parameterKey="my key" -F anotherParameterKey="special characters are allowed here" -u admin:admin https://website-url.com/api/endpoint 

Hi Pierre,

thanks for your answer.

Maybe interesting for others: I’m using Python to call the Web API. The requests library is also doing the job of parameter encoding:

params = 'isRegularExpression=true;headerFormat=//\s*<copyright> XXX'
payload = {'key': profile_key, 'rule': 'java:S1451', 'severity': 'MAJOR', 'params': params}
response = requests.post(url, payload)