API talk:Edit

Dear early adopters, does the edit action work for anyone? I try hard but can't get it to work with an php client. Like suggested at the login-discussion site i now use the Snoopy library to set the cookies for the mw system (hopefully this is not necessary anymore in the near future!). I am able to login and to request a edit-token. but if i try to edit the content, i get the result Conflict detected. Is it possible to get some more details about the conflict? Any logfiles or something else which could help?
 * Ah, found the conflict myself: i was using the false epedittime. Now it works!

Create pages
How do I need to change the code in order to create, rather than edit, a page? Thanks.

Sorry for the late response. Create and edit are the same from the API point of view. eptext=WikiText parameter is the whole article content, including changes when the article has been edited, or new content when eptitle did not exist. --Raquel.Frisa 10:07, 19 October 2007 (UTC)


 * one little difference would be useful: sometimes you want to change an article only if it exists, but not create it if it doesn't. an example: inserting a speedy-deletion-template should not recreate an already deleted article. -- ∂ 01:48, 21 October 2007 (UTC)
 * What about you just check for the article's existence using api.php?action=query&prop=info&titles=hddfal? --Catrope 12:26, 21 October 2007 (UTC)
 * Race condition -- ∂ 15:03, 25 October 2007 (UTC)
 * You'll get an w:Wikipedia:Edit conflict, won't you? --Catrope 22:16, 30 October 2007 (UTC)
 * that would only be possible if i fetched the edittoken before the article has been deleted, and there's no way to ensure that. -- ∂ 13:35, 5 November 2007 (UTC)
 * True. There should probably be an epNoCreate parameter. --Catrope 15:08, 5 November 2007 (UTC)

Can't pass &prop via php
$titleURL = "action=query&prop=info&titles=BatPresubmitTest&intoken=edit&lgtoken=". $getLoginResponse['login']['lgtoken']."&lgusername=". $getLoginResponse['login']['lguseprname']."&lguserid=". $getLoginResponse['login']['lguserid']. "&format=php";

$getTitleResponse = unserialize(getURL($apiURL,$titleURL)); function getURL($url,$vars){ $ch = curl_init; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); $content = curl_exec($ch); curl_close($ch); return $content; } No matter how I try this &prop gets encodes to &#8733; Does anyone have a clue how to that parameter without the param getting encoded/decoded to a char? --jason 04:08, 13 November 2007 (UTC)
 * That's weird. You could:
 * Try to use &amp; rather than &
 * Use Snoopy, which doesn't have this problem (and allows you to specify post data as an array instead).
 * --Catrope 14:25, 13 November 2007 (UTC)
 * Thanks - Solved with this (apparently tokens arent working - go snoopy)
 * --jason 18:03, 13 November 2007 (UTC)

function getSnooped($url,$vars){ include "Snoopy.class.php"; $snoopy = new Snoopy; $snoopy->cookies["inside_wikiToken"] = $_COOKIE["inside_wikiToken"]; $snoopy->cookies["inside_wikiUserID"] = $_COOKIE["inside_wikiUserID"]; $snoopy->cookies["inside_wikiUserName"] = $_COOKIE["inside_wikiUserName"]; $snoopy->cookies["inside_wiki_session"] = $_COOKIE["inside_wiki_session"]; $snoopy->submit($url,$vars); $snoopy->setcookies; return $snoopy->results; }

Odd - is this enabled?
Maybe I'm missing something -- heck, I probably am :)

Say, I try a request like this:

Array (   [epedittoken] => 3b70467f9655b80195b13e7765437dc0+\    [epsummary] => SxWiki: Testing    [eptext] => New revision here    [lgtoken] =>     [minoredit] => no    [epuserid] => 4746784    [testrun] => no    [disablemerge] => no ) I'm trying to send it to this URL: http://en.wikipedia.org/w/api.php?action=edit&title=User%3ASQL%2FSandbox

No matter what I do, I get:

unknown_action: Unrecognised value for parameter 'action' 1.13: Still same problem - User:Dynasource
 * Did you remember to add  to LocalSettings.php? --77.164.182.8 17:52, 9 August 2008 (UTC)

Anyone know what the likely obvious thing I'm missing is? :) SQL Query me!  04:14, 15 November 2007 (UTC)
 * This is a proposed implementation that's only partially been written and is not yet available in the main source tree. It will be when it's been completed and tested. --Catrope 13:37, 15 November 2007 (UTC)


 * Gotcha, maybe the article should say so :) SQL Query me!  21:19, 15 November 2007 (UTC)

Just out of interest does anyone have an idea about when this is likely to be implemented, or what we can do to speed it up?? :) 84.68.125.79 21:59, 5 December 2007 (UTC)
 * It's gonna be implemented eventually. The Vodafone folks were supposed to be working on this, but have been inactive lately, so I'll take up their work soon. --Catrope 14:20, 6 December 2007 (UTC)

Is there is any update on when would this Edit/Create APIs be ready? Anyone working on this? Also what is it missing to make it work? Maybe we can help making it working...., thanks in advance for the update. --66.131.255.87 03:34, 19 February 2008 (UTC)
 * Action=edit is now finished, but it hasn't been enabled on Wikipedia and friends yet. --Catrope 13:15, 12 March 2008 (UTC)

unknown_action: Unrecognised value for parameter 'action'
I have version 1.12 installed, as well as both API parameters in the LocalSettings set to true; When i make a POST request to edit (action=edit), i am getting this error:  "unknown_action: Unrecognised value for parameter 'action'". Anyone know why I would be getting this? Isn't editing supposed to be supported for version 1.12? --Duke33 19:29, 12 April 2008 (UTC)
 * Oops, that should be 1.13. --Catrope 19:56, 13 April 2008 (UTC)


 * Me too :(
 * Go back, to trying again the parsed method by browsing.
 * --Covi 11:40, 3 May 2008 (UTC)


 * action=edit seems to be available only from 1.13, i. e. there is a file includes/api/ApiEdit.php
 * I figured it out with help of http://www.markmail.org/message/r5pa4b64dtotpydy, http://www.nabble.com/Trouble-making-edit-requests-td21464948.html and my own installation. I couldn't find it anywhere in the documentation.

deadline to enable action=edit on Wikipedia?
If not soon, what method you'd suggest to use meanwhile? -- Григор Гачев 09:20, 14 August 2008 (UTC)
 * I don't think action=edit will be enabled on WMF wikis very soon. To make action=edit cooperate nicely with extensions, a rewrite of EditPage.php should really be done. I've done some of that rewriting already, but it'll take some time. In the meantime, you can use pywikipediabot. --Catrope 12:41, 15 August 2008 (UTC)
 * Sorry, I don't understand: does action=edit actually work but is disabled on Wikipedia, or is it unfinished and impossible to enable on any MediaWiki site? --217.117.119.246 02:16, 17 August 2008 (UTC)
 * action=edit works fine. It hasn't been enabled on WMF wikis (including Wikipedia) yet because it doesn't work too nicely with extensions yet. --Catrope 06:59, 17 August 2008 (UTC)
 * Is known when it will be activated on the WMF wikis? -- Fale
 * No. --Catrope 14:18, 17 August 2008 (UTC)

internal server error using edit
I´m trying to edit an article on en.wikipedia.org. The response I´m getting from the server seems ok when it returns a code error, like "cantcreate-anon" if the query doesn´t identify the user, "articleexists" if it is trying to create a page that already exists and the createonly parameter is set or "badtoken" if the token is not valid

But when the request seems to be all right I get an Internal Server Error (Http code 500).
 * This was fixed, see also 15420. --Catrope 21:20, 6 September 2008 (UTC)

Strange stuff ?
I've some problems using this editing API: Is there any info about this comportement, do I fortget someting ? I use Mediawiki 1.13.1. Charles 16:39, 5 October 2008 (UTC)
 * All parameters must be send in the url to be understand by the server, but I must use a POST request and fill the content with some dummy data. (why not passing the content of my page in the post?)
 * And the token is not received properly : the final caracter + is replaced with a space, and the token test fails.
 * You should urlencode the token so the  is encoded as  . Also, you shouldn't put dummy data in the POST body; instead, you should set the Content-Type to   and use the query string (e.g.   as the POST body. --Catrope 20:26, 5 October 2008 (UTC)
 * Ok for the urlencode. Stupid question, trivial answer... :-p
 * For the post problem, that's really strange. It works perfectly if I send a POST and send ma datas in the URL... Setting Content-Type to application/x-www-urlencoded changes nothing. URL's length is limited, so I have to fix it. If anybody have a suggestion? Charles 20:14, 6 October 2008 (UTC)
 * Ok, found. you must set content type to application/x-www-form-urlencoded (do not forget the form !). Thnak you for your help! Charles 20:20, 6 October 2008 (UTC)

token clarification
currently, the code for getting an edit token is given as follows:
 * api.php?action=query&prop=info|revisions&intoken=edit&titles=Main%20Page

this raises a question about the use of combined queries like '&prop=info|revisions'. how far can that be extended? is it restricted within general categories, or could we (if it made sense) do, say, a 'prop' and a 'list' command in the same query?

I think for the purposes of the documentation that we should drop the '|revisions' bit, which isn't necessary to get the token and last revision. I'll go ahead and edit that change in (feel free to revert if there's something I'm misunderstanding).

actually, I think there ought to be a 'API Programming Conventions' page that lays out some of these obscure details (like using a vertical bar to separate multiple options or actions, or sending combined requests). maybe combine it with the Formats page? --Ludwigs2 20:23, 14 October 2008 (UTC)
 * Stuff like  can be extended as far as you want, although duplicate values will be ignored. Combining ,   and even   in one request is also allowed. In short: in an   request, you can use any combination of query modules.
 * As I explained in my edit summary,  is not redundant, you need it to get the last revision's timestamp, which may be different from.
 * I thought using the pipe for multivalue parameters was documented somewhere, I'll check and add it if it isn't. I'll also add a note about combining query modules if there isn't one already. --Catrope 14:19, 15 October 2008 (UTC)


 * ah, ok, that makes sense. and thanks for adding the note.  :-)

Don't watch ?
Hi,

Is there an option for not modifying your watchlist, even though you have a preference like "Automatically watch all pages I edit" enabled ? The options available on the documentation are listed below. I was looking for something like the  but without "Remove".


 * : Add the page to your watchlist
 * : Remove the page from your watchlist, or don't add it even though you have a preference like "Automatically watch all pages I edit" enabled

--NicoV 10:26, 18 October 2008 (UTC)
 * No, there is no such option. I guess we kind of expect people to know whether they're watching a page and what their preferences are. --Catrope 21:00, 19 October 2008 (UTC)


 * Thanks for the answer, but when you're editing pages on Wikipedia, the effect of this option is simply to check by default the "Watch this page" checkbox, so the user still has the choice of watching or not the page. When using the API, there's no easy way (or at least, it requires other requests) to know if the edited page is watched or not. What is strange for some users is that they think this setting is only used when directly editing (where they can choose for each edit), not when they are using a tool. --NicoV 16:12, 20 October 2008 (UTC)
 * You're right that the UI supports this option in a way; I'll investigate how hard it would be to add such an option. --Catrope 15:25, 21 October 2008 (UTC)
 * Oh wait, it doesn't. I confused the option not to change one's watchlist (which is what you want) with the option to do what the UI does by default (if you don't explicitly specify whether to watch or unwatch a page, don't change the watchlist unless your preferences say otherwise). About the confusion issue: tools making edits could simply provide a ternary choice like:
 * Watch this page
 * Don't watch this page and unwatch it if I'm already watching it
 * Only watch this page if I'm already watching it or if my preferences say to watch it (neither  nor  )
 * which should be fairly clear. --Catrope 17:52, 21 October 2008 (UTC)

About the ternary choice, it's possible but far from perfect is some situations even for edits page by page. In my own case, my own tool is a maintenance tool for small edits on a lot of pages, keeping the watchlist unchanged seems the better default option. And also, when you're doing changes in batch, this choice is not really possible because the answer could be different for each page. Thanks for the answers :) --NicoV 19:16, 21 October 2008 (UTC)

How to get the section numbers of sections?
To edit a specific section I need the section number of that section. Can anybody tell me how to get the section numbers for the sections on a page?

I tried to use:

but then I get number 1 for the first section, 1.1 for a subsection and so on. I need numbers like 1, 2, 3, and so on. No matter if section or subsection. Any clues?
 * Those numbers are sequential, so you can just count 1, 2, 3, ... from the top down. The fact that this doesn't work with sections transcluded from templates is a known bug. --Catrope 14:27, 11 February 2009 (UTC)

I need JSON type Captcha error string
I'm improving Pywikipedia to use API, but I cannot test it out the captcha error by API.--Alexsh 16:22, 18 July 2009 (UTC)
 * What do you mean by "captcha error"? Do you mean what's described here? It requires a recent enough version of the ConfirmEdit extension to work. --Catrope 22:12, 24 July 2009 (UTC)

hash match failure
Hi ya'll. The article doesn't say what is returned by the server if the MD5 hashes don't match. Is it an tag or an  tag? Thanks in advance --Sanjilops 14:59, 4 September 2009 (UTC)

Embedded MediaWiki in WebSite
Hi All, I'm new to php development and mediawiki too. I saw the Api examples and there output formats. I can change the output format, but the output comes in a file to download. Any one clearly tell me what to do with that so I can use mediawiki in my website? I installed mediawiki in my website folder at localhost.

pagedeleted error
Hi,

It seems that there's a bug with some pages that have been deleted and restaured after that, but without any more modification. For example, on the French wiki, I get the error when trying to edit fr:Charbonnage. The page exists, its last version was one 2010-03-11 at 12:37:19, but it was deleted and recreated later this day (at 17:45).

Request made: http://fr.wikipedia.org/w/api.php?summary=WikiCleaner 0.99 - Correction des liens vers les pages d'homonymie&title=Charbonnage&text=...&basetimestamp=2010-03-11T12:37:19Z&token=xxxxxx+\&minor=&bot=&action=edit&format=xml

Error reported: pagedeleted - The page has been deleted since you fetched its timestamp

--NicoV 12:32, 27 March 2010 (UTC)

Long queries failing
I am trying to edit a page and the process seems to depend on the number of characters constituting my edit query. Queries as small as 500 characters work fine, but longer queries fail with the following error.

 Request: POST http://tr.wikipedia.org/w/api.php, from 88.226.155.228 via sq35.wikimedia.org (squid/2.7.STABLE7) to Error: ERR_INVALID_REQ, errno [No Error]

Any suggestions? --Superyetkin 18:27, 4 April 2010 (UTC)


 * Okay, the solution is here. Hope this helps someone. --Superyetkin 20:21, 4 April 2010 (UTC)
 * Thanks to your hint I finally could make my script working :-) Many thanks Superyetkin --Od1n

action=edit 'bot' parameter
The text of the manual reads:
 * bot: If set, mark the edit as bot, even if you are using a bot account the edits will not be marked unless you set this flag

What if you set this parameter for a non-bot account? Why do bot accounts have to set this flag at all? Cheers, --Dmb 22:40, 28 January 2011 (UTC)

text from a file
Does anybody know how can I upload text from a file for a particular section? Thanks.