AUKA
AUKA

Reputation: 139

MediaWiki API - Editing a page from Excel - <error code="mustposttoken" ...>

I am getting the following error trying to issue an edit command via the MediaWiki API.

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

This is the code I am using in Excel:

 Dim objHTTP As New WinHttp.WinHttpRequest
 URL = "http://wiki.address.net/w/api.php?format=json&action=edit&title=TestPage&section=0&text=testing123&token=" & strEditToken
 objHTTP.Open "POST", URL, False
 objHTTP.Send
 Debug.Print objHTTP.ResponseText

I have a separate part of the code where I log in and retrieve a csrf token. The code has worked before the most recent update to Media Wiki 1.24.1

Upvotes: 0

Views: 583

Answers (2)

AUKA
AUKA

Reputation: 139

I solved the issue by reviewing my POST from VBA. Set the user-agent and content-type. Also, lower-cased the title of the page in the URL string.

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://wiki.address.net/w/api.php"
strEditToken = "####################"
objHTTP.Open "POST", URL, False
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.SetRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.Send ("format=json&action=edit&title=" & lcase("TestPage") & "&section=0&text=testing123&token=" & strEditToken")

Upvotes: 0

MaxSem
MaxSem

Reputation: 3547

You're posting the token in the URL, while for security reasons it must be in request body.

Upvotes: 3

Related Questions