A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

API,userrights,RestSharp

JohnTreeHunt

I have MW ver. 1.26.2 and become problems with api.php?action=userrights&user=aaTestname3&add=moderator&format=json

Response says: {"userrights":{"user":"AaTestname3","userid":515,"removed":[],"added":[]}}

But no moderator right was added when i look in User-admin. I am currently logged in with a sysop user. I am pretty sure I have enough access in the RestSharp context.

Is that a well known problem in 1.26.2?

The token did not work from the querystring for action=userrights. This was not documentet in API documentation. For other methods it worked direct in querystring.

I got thist result: And in order to remove:

<error code="mustposttoken" info="The token parameter was found in the query string, but must be in the POST body" xml:space="preserve">

…i tried adding the token to request body, but that did not work.

After testing different methods, I found this method that worked:

request.AddParameter("token", userrightstoken.ToLower(), ParameterType.GetOrPost);

Here is also my HTTP Request and Response

-############### = censored

RestSharp request:

Postman-Token=c50a89a4-7738-###############
Cache-Control=no-cache
Accept=application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
Postman-Token=d67f0f62-a98b-4f9b-#################
Cache-Control=no-cache
token=267de0fd01f191498#################

RestSharp response:

X-Content-Type-Options=nosniff
X-Frame-Options=SAMEORIGIN
Content-Encoding=
Vary=Accept-Encoding
Transfer-Encoding=chunked
Cache-Control=private, must-revalidate, max-age=0
Content-Type=application/json; charset=utf-8
Date=Thu, 26 Apr 2018 07:22:15 GMT
Server=Apache
Tgr

It’s not very clear what you are asking or saying. Also those responses are not accurate. https://test.wikipedia.org/w/api.php?action=userrights&user=aaTestname3&add=moderator&format=json will yield

{
    "error": {
        "code": "notoken",
        "info": "The \"token\" parameter must be set.",
        "*": "See https://test.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes."
    },
    "warnings": {
        "userrights": {
            "*": "Unrecognized value for parameter \"add\": moderator."
        }
    },
    "servedby": "mw1317"
}

and https://test.wikipedia.org/w/api.php?action=userrights&user=aaTestname3&add=moderator&format=json&token=aaaa will yield

{
    "error": {
        "code": "mustpostparams",
        "info": "The following parameter was found in the query string, but must be in the POST body: token.",
        "*": "See https://test.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes."
    },
    "warnings": {
        "userrights": {
            "*": "Unrecognized value for parameter \"add\": moderator."
        }
    },
    "servedby": "mw1344"
}

which is pretty descriptive to me.