PATCH api/v2/users-management/users/{id} - content-type?

Hello,

I’m doing some tests with the new V2 API endpoints and I have trouble updating an user using the endpoint api/v2/users-management/users/{id}.

I followed the Web API documentation, but I can’t make this work in my python project.Context:

The python requests library, using a Session object to cache authentication data. The session object has the following configuration:

session.auth = requests.auth.HTTPBasicAuth(sonarqube_token)
session.headers = {"Accept": "application/json", "Content-Type": "application/json"}

Basically, I’m calling

session.request(
            method="PATCH",
            url=self.configuration.host + "/api/v2/users-management/users/{my_user_id}",
            params={},
            data={
                "name": "New name"
            },
            timeout=30,
        )

Whatever I put in the request body, I’m getting a 415 Client Error.

Is there something I’m doing wrong ?

Thanks !

Hey there.

These are the headers when SonarQube is making the API call

Accept:

application/json, text/plain, */*

Content-Type:

application/merge-patch+json

Does that resolve the 415 error? If so, I’ll flag this for attention because that should be documented somewhere :face_with_spiral_eyes:

Hey @Colin !

Thanks for the quick response, it solves indeed the issue. I agree, mentioning the content type of the query ± the “Accept” header would really help :wink:

Thanks again, see you !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.