Core REST API/Reference/Pages/Create page

POST /core/v1/{project}/{language}/page

Creates a wiki page.

Examples

curl

# Create a user sandbox page on English Wikipedia
$ curl -X POST https://api.wikimedia.org/core/v1/wikipedia/en/page \
-H "Content-Type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
--data '{"source": "Hello, world!", "title": "User:YOUR_USERNAME/Sandbox", "comment": "Creating a test page with the Wikimedia API"}'

Python

# Python 3
# Create a user sandbox page on English Wikipedia

import requests
import json

url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page'
request_data = {
    'source': 'Hello, world!',
    'title': 'User:YOUR_USERNAME/Sandbox',
    'comment': 'Creating a test page with 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.post( url, headers=headers, data=json.dumps(request_data) )
output = response.json()
print(output)

PHP

<?php
// Create a user sandbox page on English Wikipedia

$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page';
$fields = [
    'source' => 'Hello, world!',
    'title' => 'User:YOUR_USERNAME/Sandbox',
    'comment' => 'Creating a test page with the Wikimedia API'
];
$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_POST, true );
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

// Create a user sandbox page on English Wikipedia

let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page';
let response = await fetch( url,
    {
        method: 'POST',
        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!',
            'title': 'User:YOUR_USERNAME/Sandbox',
            'comment': 'Creating a test page with the Wikimedia API'
        })
    }
);
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.

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 creating the page. To allow the comment to be filled in by the server, use "comment": null.
content_model

required string

Page content format:

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

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: Page already exists.
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"
}