I want to login to Wikidata using their API: https://www.wikidata.org/w/api.php
I had prepared a few requests and tried them against the test instance of Wikidata: https://test.wikidata.org/w/api.php. Everything worked fine and I changed the call to target the real Wikidata instead. But now the action clientlogin
won't work, even though the settings are exactly the same as for the test instance. I have looked for documentation, but none seem to describe any differences between the test and the real instance.
I'm using Postman for making the POST requests. I have the parameters:
action:clientlogin
format:json
loginreturnurl:http://example.com
username:myUsername
and the body has format form-data with values:
logintoken:8227d28de0a94affe9779db047c40df8609542dc+\
password:myPassword
This works fine for test, but when I call the real Wikidata, I get the following error:
Call: https://wikidata.org/w/api.php?action=clientlogin&format=json&loginreturnurl=http://example.com&username=myUsername
{
"error": {
"code": "missingparam",
"info": "The \"logintoken\" parameter must be set.",
"*": "See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
},
"servedby": "mw1315"
}
If I put the logintoken as a parameter, I get this error:
Call: https://wikidata.org/w/api.php?action=clientlogin&format=json&loginreturnurl=http://example.com&logintoken=8227d28de0a94affe9779db047c40df8609542dc+\&username=myUsername
{
"error": {
"code": "mustpostparams",
"info": "The following parameter was found in the query string, but must be in the POST body: logintoken.",
"*": "See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
},
"servedby": "mw1289"
}
I have made the appropriate calls for logintokens, but I have excluded that in those calls, since I not that if it works, it will give the error of invalid token.
While writing this question, I realized that the error was that when removing the subdomain test from the URL, I was supposed to replace it with www for the real Wikidata... 🤦🏻♀️ But now it works and hopefully, someone else can make use of this answer.