PUT /core/v1/{project}/{language}/page/{title}

Edits a page based on the page's latest revision ID, or creates the page if no revision ID is given. To get the latest version of a page's source and revision ID, call the get page source endpoint. Most wiki pages are written in MediaWiki-flavored Wikitext.

In the event of a merge conflict, the API attempts to resolve the conflict automatically. If the edit conflict cannot be resolved, the API returns a 409 error.

Examples

curl

# Update the sandbox page on English Wikipedia with "Hello, world!"
$ curl -X PUT https://api.wikimedia.org/core/v1/wikipedia/en/page/Wikipedia:Sandbox \
-H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
--data '{"source": "Hello, world!", "comment": "Testing out the Wikimedia API", "latest": { "id": LATEST_REVISION_ID }}'

Python

# Python 3
# Update the sandbox page on English Wikipedia with "Hello, world!"

import requests
import json

url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Wikipedia:Sandbox'
request_data = {
    'source': 'Hello, world!',
    'latest': { 'id': 'LATEST_REVISION_ID' },
    'comment': 'Testing out the Wikimedia API',
}

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}

response = requests.put( url, headers=headers, data=json.dumps(request_data) )
output = response.json()
print(output)

PHP

<?php
// Update the sandbox page on English Wikipedia with "Hello, world!"

$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Wikipedia:Sandbox';
$fields = [
    'source' => 'Hello, world!',
    'comment' => 'Testing out the Wikimedia API',
    'latest' => [
        'id' => LATEST_REVISION_ID
    ]
];
$json = json_encode( $fields );

$token = 'YOUR_ACCESS_TOKEN';
$authorization = 'Authorization: Bearer ' . $token;

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>

JavaScript

// Update the sandbox page on English Wikipedia with "Hello, world!"

let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Wikipedia:Sandbox';
let response = await fetch( url,
    {
        method: 'PUT',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
            'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
        },
        body: JSON.stringify({
            'source': 'Hello, world!',
            'comment': 'Testing out the Wikimedia API',
            'latest': { 'id': LATEST_REVISION_ID }
        })
    }
);
response.json()
    .then(console.log).catch(console.error);

Parameters

project

required path

Project name. For example: wikipedia (encyclopedia articles), commons (images, audio, and video), wiktionary (dictionary entries). List all projects.
language

required path

Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
Note: The language parameter is prohibited for commons and other multilingual projects.
title

required string

Wiki page title

Request schema

source

required string

Page content in the format specified by the content_model property
title

required string

Page title. Visit individual wikis for policies about page title formats and characters. For example, for English Wikipedia, visit Article titles.
comment

required string

Reason for editing the page. To allow the comment to be filled in by the server, use "comment": null.
content_model

required string

Page content format:
lastest

object

Information about the latest version of the page. You can fetch this information from the get page source endpoint.
Properties
id

integer

Revision identifier for the latest revision, required to edit a page. To create a page, omit this property.

Headers

Content-Type

required

Specify application/json as the content type.
Authorization

required

Include an access token using the Bearer authentication scheme. For more information about obtaining an access token, visit Authentication.

Responses

200 Success: Page updated. Returns a page with the source property.
Example
{
  "id": 9228,
  "key": "Earth",
  "title": "Earth",
  "latest": {
    "id": 989181479,
    "timestamp": "2020-11-17T14:42:31Z"
  },
  "content_model": "wikitext",
  "license": {
    "url": "//creativecommons.org/licenses/by-sa/3.0/",
    "title": "Creative Commons Attribution-Share Alike 3.0"
  },
  "source": "{{Short description|Third planet from the Sun in the Solar System}}\n{{About|the planet|its human aspects|World|other uses|Earth (disambiguation)|and|Planet Earth (disambiguation)}}\n{{pp-semi|small=yes}}\n{{Use American English|date=August 2019}}\n{{Use dmy dates|date=January 2020}}\n{{Featured article}}\n\n{{Infobox planet...}}"
}
201 Success: Page created. Returns a page with the source property.
Example
{
  "id": 9228,
  "key": "Earth",
  "title": "Earth",
  "latest": {
    "id": 989181479,
    "timestamp": "2020-11-17T14:42:31Z"
  },
  "content_model": "wikitext",
  "license": {
    "url": "//creativecommons.org/licenses/by-sa/3.0/",
    "title": "Creative Commons Attribution-Share Alike 3.0"
  },
  "source": "{{Short description|Third planet from the Sun in the Solar System}}\n{{About|the planet|its human aspects|World|other uses|Earth (disambiguation)|and|Planet Earth (disambiguation)}}\n{{pp-semi|small=yes}}\n{{Use American English|date=August 2019}}\n{{Use dmy dates|date=January 2020}}\n{{Featured article}}\n\n{{Infobox planet...}}"
}
400 Error: Bad content model. Include a valid content_model.
Example
{
  "messageTranslations": {
    "en": "Bad content model: incorrect"
  },
  "httpCode": 400,
  "httpReason": "Bad Request"
}
401 Error: Missing token. Include an access token in an Authorization request header using the Bearer authentication scheme.
Example
{
  "httpCode": 401,
  "httpReason": "Jwt is missing"
}
409 Error: Edit conflict. The error response includes the differences between the base revision specified in the request and the latest published revision. Visit the compare revisions endpoint for the diff schema.
Example
{
  "messageTranslations": {
    "en": "Edit conflict."
  },
  "httpCode": 409,
  "httpReason": "Conflict"
}
415 Error: Unsupported Content-Type. Add the request header Content-Type: application/json.
Example
{
  "message": "Unsupported Content-Type",
  "content_type": "incorrect",
  "httpCode": 415,
  "httpReason": "Unsupported Media Type"
}