User:User:Dikshagupta99/Sandbox/API:Get the contents of a page

There are three main methods for retrieving page contents via the API:


 * 1) Get data about the set of pages by setting titles or page ids(for retrieving wikitext)
 * 2) Specify content explicitly using text, title, revision id(revid) and content model(for retrieving parsed content)
 * 3) Return plain text or limited HTML extracts of a given page.

Method 1: Get revised page data from API: Revisions
There are several ways of getting the revised data:


 * 1) Get data about a set of pages (last revision), by setting titles or page ids.
 * 2) Get revisions for one given page, by using titles or page ids with start, end, or limit.
 * 3) Get data about a set of revisions by setting their IDs with revision ids.

Example 1
The below GET request is to obtain revised data of the page.

Response
{| class="wikitable" !API Endpoint !Wiki
 * + Examples of Wikimedia Wiki Endpoints
 * MediaWiki API|-
 * Meta-Wiki API
 * English Wikipedia API|-
 * Dutch Wikipedia API|-
 * Wikimedia Commons API
 * Test Wiki API|}
 * Dutch Wikipedia API|-
 * Wikimedia Commons API
 * Test Wiki API|}
 * Wikimedia Commons API
 * Test Wiki API|}
 * Test Wiki API|}

Introduction
The MediaWiki action API is a web service that allows access to some wiki-features like authentication, page operations, and search. It can provide meta information about the wiki and the logged-in user.

Uses for the MediaWiki Action API
Monitor a MediaWiki installation Create a bot to maintain a MediaWiki installation Log into a wiki, access data, and post changes by making HTTP requests to the web service

Getting started with MediaWiki action API
Before you start using the MediaWiki action API, you should review the following pages: The faq>Special:MyLanguage/API:FAQ|FAQ. The page about [[Special:MyLanguage/API:Data formats The page about [[Special:MyLanguage/API:Errors and warnings The page about [[Special:MyLanguage/API:Etiquette Any policies that apply to the wiki you want to access, such as Wikimedia Foundation wikis\' [[wmf:Special:MyLanguage/Terms of Use [[wmf:Special:MyLanguage/trademark policy These terms apply to you when you access or edit using the API, just as they do when you use your web browser.
 * input and output formats]]
 * errors and warnings]]
 * etiquette]]
 * terms of use]],
 * trademark policy]].

Other APIs
If you do not find what you are looking for in this API documentation, there are many other APIs related to Wikimedia projects. See the [[Special:MyLanguage/API:Web APIs hub for information on other APIs for Wikimedia project data and their usage.
 * Web APIs hub]]

Code stewardship
{{feedback } }
 * author = Core Platform Team
 * irc = mediawiki-core\n|phab = mediawiki-api

'}}}]

For the sample codes, view

Method 2: Get the content of a page by API: Parsing_wikitext
There are several ways to specify the text to parse:


 * 1) Specify a page or revision, using page, page id, or old id.
 * 2) Specify content explicitly, using text, title, revision id, and content model.
 * 3) Specify only a summary to parse. property(prop) should be given an empty value.

For more details regarding API:Parsing_wikitext view

Example
GET request to get parsed content of a page:Pet door

Response
 ^ <cite class="citation web">"World's first Passive House-certified pet door unveiled at Ecobuild 2014"</a>. www.gizmag.com. Retrieved 2016-07-07. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=www.gizmag.com&amp;rft.atitle=World%27s+first+Passive+House-certified+pet+door+unveiled+at+Ecobuild+2014&amp;rft_id=http%3A%2F%2Fwww.gizmag.com%2Fpassive-house-petwalk-door%2F31162%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <style data-mw-deduplicate="TemplateStyles:r886058088">.mw-parser-output cite.citation{font-style:inherit}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation .cs1-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration{color:#555}.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration span{border-bottom:1px dotted;cursor:help}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/12px-Wikisource-logo.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output code.cs1-code{color:inherit;background:inherit;border:inherit;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;font-size:100%}.mw-parser-output .cs1-visible-error{font-size:100%}.mw-parser-output .cs1-maint{display:none;color:#33aa33;margin-left:0.3em}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-right{padding-right:0.2em} </li> <li id="cite_note-2"> ^</a> <cite class="citation web">"Automated Pet Doors&#160;: pet door"</a>. Retrieved 2016-07-07. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Automated+Pet+Doors+%3A+pet+door&amp;rft_id=http%3A%2F%2Fwww.trendhunter.com%2Ftrends%2Fpet-door&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> <li id="cite_note-3"> ^</a> <cite class="citation web">"PetWALK Automatic Pet Door Prevents Wet Paw Marks Around The Home"</a>. Ubergizmo. 2014-03-13 . Retrieved 2016-07-07. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Ubergizmo&amp;rft.atitle=PetWALK+Automatic+Pet+Door+Prevents+Wet+Paw+Marks+Around+The+Home&amp;rft.date=2014-03-13&amp;rft_id=http%3A%2F%2Fwww.ubergizmo.com%2F2014%2F03%2Fpetwalk-automatic-pet-door-prevents-wet-paw-marks-around-the-home%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> <li id="cite_note-4"> ^</a> Oxford English Dictionary (full ed.), 2005. </li> <li id="cite_note-NatGeo_2004-5"> ^</a> <cite class="citation web">"Oldest Known Pet Cat? 9500-year-old Burial Found on Cyprus"</a>. National Geographic News. National Geographic Society. April 8, 2004. Retrieved March 6, 2007. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=National+Geographic+News&amp;rft.atitle=Oldest+Known+Pet+Cat%3F+9500-year-old+Burial+Found+on+Cyprus&amp;rft.date=2004-04-08&amp;rft_id=http%3A%2F%2Fnews.nationalgeographic.com%2Fnews%2F2004%2F04%2F0408_040408_oldestpetcat.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> <li id="cite_note-6"> ^</a> <cite class="citation web">Anonymous ("The Country Parson") (1863). E. H. Sears &amp; Rufus Ellis (ed.). "Random Readings: Philosophy and Common Sense"</a>. The Monthly Religious Magazine. Boston, MA: Leonard C. Bowles Press. p.&#160;298. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Monthly+Religious+Magazine&amp;rft.atitle=Random+Readings%3A+Philosophy+and+Common+Sense&amp;rft.pages=298&amp;rft.date=1863&amp;rft.au=Anonymous+%28%22The+Country+Parson%22%29&amp;rft_id=https%3A%2F%2Fbooks.google.com%2Fbooks%3Fid%3DPXYUAAAAYAAJ%26pg%3DPA298&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> <li id="cite_note-7"> ^</a> Brodetsky, S. (2007) [first pub. 1927]. Sir Isaac Newton. Upton Press. p. 100. <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/>ISBN</a>&#160;1406769991</a>. </li> <li id="cite_note-8"> ^</a> More, Louis Trenchard (1937). Isaac Newton: a Biography. C. Scribner's Sons. </li> <li id="cite_note-9"> ^</a> Wright, J. F. M. (1827). Alma Mater. Volume 1. p. 17. </li> <li id="cite_note-10"> ^</a> <cite class="citation web"><a rel="nofollow" class="external text" href="http://www.petplan.co.uk/petcensus/censusinfo.pdf">"Petplan Pet Census 2011"</a> (PDF). Petplan. p.&#160;15. Retrieved September 11, 2012. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Petplan+Pet+Census+2011&amp;rft.pages=15&amp;rft.pub=Petplan&amp;rft_id=http%3A%2F%2Fwww.petplan.co.uk%2Fpetcensus%2Fcensusinfo.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> <li id="cite_note-11"> <a href="#cite_ref-11">^</a> <cite class="citation web">Woods, Amanda. <a rel="nofollow" class="external text" href="https://medium.com/@woodsamanda399/7-important-measures-to-pet-proof-your-home-bdd3e33ae4c8">"7 Important Measures to Pet Proof Your Home"</a>. Retrieved 23 August 2017. <span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=7+Important+Measures+to+Pet+Proof+Your+Home&amp;rft.aulast=Woods&amp;rft.aufirst=Amanda&amp;rft_id=https%3A%2F%2Fmedium.com%2F%40woodsamanda399%2F7-important-measures-to-pet-proof-your-home-bdd3e33ae4c8&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3APet+door" class="Z3988"> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886058088"/> </li> </ol>

Method 3: Get the content of the page using Extension: TextExtracts#API
The TextExtracts extension provides an API which allows to retrieve plain-text or limited HTML extracts of page content.

Example
Get a 100-character extract:

Download Extension
To download extension view-