Topic on Project:Village Pump

How to test MediaWiki api with action="edit"?

7
Nghiem419ddt (talkcontribs)

I want to add some links into "External links" section of some wikipedia pages, so I write an application using mediawiki api with "action=edit" to do this.

(https://en.wikipedia.org/w/api.php)

Do I have permission to do this? If yes, could you please tell me how to update this section using mediawiki api and how to test this api? Because I cannot post a request to update an existing wikipedia page.

Thank you very much.

Best regards,

Kevin

Mainframe98 (talkcontribs)
Nghiem419ddt (talkcontribs)

Hi,

I can get the content of "External links", the content is the string as below

==External links==
*[http://tellurideskiresort.com/ Telluride Ski Resort]
*[http://www.coloradoskihistory.com/areahistory/telluride.html ColoradoSkiHistory.com - Telluride Ski Area]
*[http://www.weatherunderground.com/cgi-bin/findweather/getForecast?query=81435 Telluride Weather Forecast - WeatherUnderground.com]
*[http://www.visittelluride.com/ Telluride Tourism Board Official Site]
*[http://www.3dskimaps.com/index.php?path=telluride 3dSkiMap of Telluride Ski Resort]

[[Category:Ski areas and resorts in Colorado]]
[[Category:Buildings and structures in San Miguel County, Colorado]]
[[Category:Visitor attractions in San Miguel County, Colorado]]

And then I using a method to update this string to

==External links==
*[http://www.mydomain.com/ My website]
*[http://tellurideskiresort.com/ Telluride Ski Resort]
*[http://www.coloradoskihistory.com/areahistory/telluride.html ColoradoSkiHistory.com - Telluride Ski Area]
*[http://www.weatherunderground.com/cgi-bin/findweather/getForecast?query=81435 Telluride Weather Forecast - WeatherUnderground.com]
*[http://www.visittelluride.com/ Telluride Tourism Board Official Site]
*[http://www.3dskimaps.com/index.php?path=telluride 3dSkiMap of Telluride Ski Resort]

[[Category:Ski areas and resorts in Colorado]]
[[Category:Buildings and structures in San Miguel County, Colorado]]
[[Category:Visitor attractions in San Miguel County, Colorado]]

And then I call this api "https://en.wikipedia.org/w/api.php" to post with the json

{
	"action":"edit",
	"contentformat":"text/x-wiki",
	"token":"8ecd52629cc8a27469fa65f9b8ecc0b2580900bb%2B%5C",
	"title":"Telluride_Ski_Resort",
	"section":"17",
	"text":"==External links==\n*[http://www.mydomain.com/ My website]\r\n*[http://tellurideskiresort.com/ Telluride Ski Resort]\n*[http://www.coloradoskihistory.com/areahistory/telluride.html ColoradoSkiHistory.com - Telluride Ski Area]\n*[http://www.weatherunderground.com/cgi-bin/findweather/getForecast?query=81435 Telluride Weather Forecast - WeatherUnderground.com]\n*[http://www.visittelluride.com/ Telluride Tourism Board Official Site]\n*[http://www.3dskimaps.com/index.php?path=telluride 3dSkiMap of Telluride Ski Resort]\n\n[[Category:Ski areas and resorts in Colorado]]\n[[Category:Buildings and structures in San Miguel County, Colorado]]\n[[Category:Visitor attractions in San Miguel County, Colorado]]",
	"format":"json",
	"assert":"user"
}

Is it correct? Thank you very much.

Best regards,

Kevin

Mainframe98 (talkcontribs)

I believe the contenttype should reflect the way you are presenting the POST request, so it should be application/x-www-form-urlencoded according to API:Edit. I never got it working with contenttype set to json, so I can't offer any insight into that.

Nghiem419ddt (talkcontribs)

If I use application/x-www-form-urlencoded, I cannot post a long and complicated string in "text" parameter

Legoktm (talkcontribs)

To be clear, posting JSON to the API will not work - you need to post a form basically with the values, and you should be able to post as long of a string as you want in the text parameter.

Additionally, if you want to run a script on the English Wikipedia, you need to have it approved first. You should read their guidelines and policies about bots first.

Nghiem419ddt (talkcontribs)

Thanks Legoktm

Reply to "How to test MediaWiki api with action="edit"?"