apipostsonarqubesonarqube-4.5

Create custom rules with params through API


I'm trying to create a XPath custom rule with the Sonar API, but I have an issue when adding the parameters.

Here is my HTTP request :

    http.sendPostRequest("http://localhost:9000/api/rules/create" 
            + "?custom_key=test" 
            + "&markdown_description=test" 
            + "&name=test"
            + "&params=expression=test;filePattern=test;message=test" 
            + "&severity=BLOCKER" 
            + "&template_key=xml:XPathCheck");

I receive a code 200 and the rule is created in Sonar, except the parameters "params" are empty.

I've checked the API's documentation, it says it should be something like "params=key1=v1;key2=v2", it meets this format but still doesn't work.


Solution

  • It's not possible to use a key that was already used by another key, even when this rule is removed. You need to add the parameter prevent_reactivation=true in order to fail if a rule already exists with this key.