API:Creación de cuentas

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Account creation and the translation is 29% complete.

Other languages:
Deutsch • ‎English • ‎dansk • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎română • ‎български • ‎русский • ‎العربية • ‎ไทย • ‎中文 • ‎日本語 • ‎한국어
Versión de MediaWiki: 1.27
This page documents the account creation API as of MediaWiki 1.27. Documentation of the API as it existed in earlier versions is available here: Api:Account creation/pre-1.27 .

Documentación de API

action=createaccount (create)

(main | createaccount)
  • This module requires write rights.
  • This module only accepts POST requests.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Create a new user account.

The general procedure to use this module is:

  1. Fetch the fields available from action=query&meta=authmanagerinfo with amirequestsfor=create, and a createaccount token from action=query&meta=tokens.
  2. Present the fields to the user, and obtain their submission.
  3. Post to this module, supplying createreturnurl and any relevant fields.
  4. Check the status in the response.
    • If you received PASS or FAIL, you're done. The operation either succeeded or it didn't.
    • If you received UI, present the new fields to the user and obtain their submission. Then post to this module with createcontinue and the relevant fields set, and repeat step 4.
    • If you received REDIRECT, direct the user to the redirecttarget and wait for the return to createreturnurl. Then post to this module with createcontinue and any fields passed to the return URL, and repeat step 4.
    • If you received RESTART, that means the authentication worked but we don't have a linked user account. You might treat this as UI or as FAIL.

Only use these authentication requests, by the id returned from action=query&meta=authmanagerinfo with amirequestsfor=create or from a previous response from this module.

Separate values with | or alternative. Maximum number of values is 50 (500 for bots).

Format to use for returning messages.

One of the following values: html, wikitext, raw, none
Default: wikitext

Merge field information for all authentication requests into one array.

Type: boolean (details)

Preserve state from a previous failed login attempt, if possible.

If action=query&meta=authmanagerinfo returned true for hasprimarypreservedstate, requests marked as primary-required should be omitted. If it returned a non-empty value for preservedusername, that username must be used for the username parameter.

Type: boolean (details)

Return URL for third-party authentication flows, must be absolute. Either this or createcontinue is required.

Upon receiving a REDIRECT response, you will typically open a browser or web view to the specified redirecttarget URL for a third-party authentication flow. When that completes, the third party will send the browser or web view to this URL. You should extract any query or POST parameters from the URL and pass them as a createcontinue request to this API module.


This request is a continuation after an earlier UI or REDIRECT response. Either this or createreturnurl is required.

Type: boolean (details)

A "createaccount" token retrieved from action=query&meta=tokens

This parameter is required.
This module accepts additional parameters depending on the available authentication requests. Use action=query&meta=authmanagerinfo with amirequestsfor=create (or a previous response from this module, if applicable) to determine the requests available and the fields that they use.

Crear una cuenta

El proceso tiene tres pasos generales:

  1. Fetch the fields from API:Authmanagerinfo and the token from API:Tokens .
  2. Send a POST request with the fetched token, user information and other fields, and return URL to the API.
  3. Deal with the response, which might involve further POST requests to supply more information.

Example 1: Process on a wiki without special authentication extensions

A wiki without special authentication extensions can be rather straightforward. If your code knows which fields will be required, it might skip the call to API:Authmanagerinfo and just assume which fields will be needed (i.e. username, password & retyped password, email, possibly realname).

If you are creating an account for someone else, you'll need to specify a reason for the same by including a reason parameter to the POST request. You could also use mailpassword in place of password and retype parameters to have MediaWiki send the new user a temporary password via email.

POST request


    "createaccount": {
        "status": "PASS",
        "username": "Zane"

Código de ejemplo




    MediaWiki Action API Code Samples
    Demo of `createaccount` module: Create an account on a wiki without the 
    special authentication extensions

    MIT license

import requests

S = requests.Session()

WIKI_URL = "https://test.wikipedia.org"
API_ENDPOINT = WIKI_URL + "/w/api.php"

# First step
# Retrieve account creation token from `tokens` module

PARAMS_0 = {

R = S.get(url=API_ENDPOINT, params=PARAMS_0)
DATA = R.json()

TOKEN = DATA['query']['tokens']['createaccounttoken']

# Second step
# Send a post request with the fetched token and other data (user information,
# return URL, etc.)  to the API to create an account

PARAMS_1 = {
    'action': "createaccount",
    'createtoken': TOKEN,
    'username': 'your_username',
    'password': 'your_password',
    'retype': 'retype_your_password',
    'createreturnurl': WIKI_URL,
    'format': "json"

R = S.post(API_ENDPOINT, data=PARAMS_1)
DATA = R.json()


Example 2: Process on a wiki with a CAPTCHA extension

Note the first step below could, if you'd rather, be done as two steps: one to fetch the fields available from API:Authmanagerinfo and another to fetch the token from API:Tokens .

First step: Fetch fields available from API:Authmanagerinfo and token from API:Tokens

Second step: Send a post request along with a create account token, user information and return URL

Código de ejemplo

Note this code sample separates the API:Authmanagerinfo and API:Tokens requests, and generally assumes there will be a CAPTCHA and no other complications.

Example 3: Account creation on a wiki with a CAPTCHA, an OpenID extension, and a two-factor authentication extension enabled

First step: Fetch fields available from API:Authmanagerinfo and token from API:Tokens

The fetching of API:Authmanagerinfo and API:Tokens is largely the same as in the previous example, and so is not repeated here. The list of requests returned by API:Authmanagerinfo will include definitions for both the CAPTCHA extension and the OpenID extension.

Second step: Answer the CAPTCHA and select OpenID authentication.

The client would be expected to redirect the user's browser to the provided redirecttarget.

The OpenID provider would authenticate, and redirect to Special:OpenIDConnectReturn on the wiki, which would validate the OpenID response and then redirect to the createreturnurl provided in the first POST to the API with the code and state parameters added.

The client gets control of the process back at this point and makes its next API request.

Third step: Back from OpenID.

The client posts the code and state back to the API. The API's response has the two-factor authentication extension prompting the user to set up their second factor.

Now the client would prompt the user to set up a new account in their two-factor authentication app and enter the current code, or allow the user to skip 2FA setup. Let's assume the user does set up 2FA.

Fourth step: Set up two-factor authentication.

The account creation has finally succeeded.

If at any point account creation fails, a response with status FAIL will be returned, along with a message to display to the user.

Errores posibles

Código Información
badtoken Invalid create account token
notoken Se debe establecer el parámetro token.
mustpostparams Se encontró el siguiente parámetro en la cadena de la consulta, pero deben estar en el cuerpo del POST: createtoken.
missingparam Al menos uno de los parámetros "createcontinue" y "createreturnurl" es necesario.
authmanager-create-no-primary Las credenciales suministradas no pueden usarse para la creación de la cuenta.
invalidemailaddress No se puede aceptar la dirección de correo electrónico, pues parece que tiene un formato no válido.

Por favor, escribe una dirección bien formada o deja el campo en blanco.

badretype Las contraseñas no coinciden.
userexists El nombre de usuario indicado ya está en uso.

Elige un nombre diferente.

captcha-createaccount-fail Falta el código CAPTCHA, o éste es incorrecto.
acct_creation_throttle_hit Los visitantes a este wiki que utilizaron su dirección IP han creado num cuentas en las últimas 24 horas, lo cual es el máximo permitido en ese período de tiempo.

Como resultado, los visitantes que utilicen esa dirección IP no pueden crear más cuentas de usuario en este momento.

Si estás en un evento cuyo objeto es contribuir a los proyectos Wikimedia, por favor visite esta página para resolver el problema.

Documentos adicionales

Si has iniciado sesión, tu nombre de usuario también se registrará al crear una cuenta.

  • While executing the code snippets provided on this page, remember:
    • Once an account on a wiki is created, it cannot be deleted.
    • Always use https://test.wikipedia.org/w/api.php as the endpoint, so that you don't accidentally create accounts on production wikis.
  • MediaWiki site administrators and extension developers can disable this API feature by inserting the following line in the configuration file:
$wgAPIModules['createaccount'] = 'ApiDisabled';

Véase también