Jump to content

Wikifunctions API

From mediawiki.org

The Wikifunctions API lets you discover and interact with Wikifunctions, a library of code functions to support the Wikimedia projects and beyond, in the world's natural and programming languages.

Documentation

[edit]

Reference

[edit]

Guides

[edit]

Quick start

[edit]
# Fetch the object with unique ID Z801 from the Wikifunctions library of functions
$ curl 'https://www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids=Z801&format=json'

Try it out

Access policy

[edit]

See Wikimedia APIs/Access policy.

Rate limits

[edit]

During March and April 2026, rate limits will be gradually transitioning to use the global Wikimedia API limits.

Fetch object

[edit]
Method
GET
Path
www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids={objectid}&format=json

Fetches and retrieves one or more Object pages from Wikifunctions. Every requested Object will be returned as a string encoding its canonical JSON representation. If a particular language is requested, the Object labels will be filtered to return only the selected or most relevant language available.

Model documentation

[edit]

Examples

[edit]

curl

[edit]
# Fetch the object with unique ID Z801 from the Wikifunctions library of functions
$ curl 'https://www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids=Z801&format=json'

Python

[edit]
# Python 3
# Fetch the object with unique ID Z801 from the Wikifunctions library of functions

import requests

zid = 'Z801'
url = 'https://www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids=' + zid + '&format=json'

response = requests.get(url)
data = response.json()
print(data)

PHP

[edit]
<?php
// Fetch the object with unique ID Z801 from the Wikifunctions library of functions

$zid = 'Z801';
$url = 'https://www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids=' . zid . '&format=json';

$ch = curl_init( $url );
$output = curl_exec( $ch );
curl_close( $ch );

echo( $output );
?>

JavaScript

[edit]
// Fetch the object with unique ID Z801 from the Wikifunctions library of functions

let zid = 'Z801';
let url = 'https://www.wikifunctions.org/w/api.php?action=wikilambda_fetch&zids=' + zid + '&format=json';

let response = await fetch( url );
response.json()
    .then(console.log)
    .catch(console.error);

Parameters

[edit]
zids

required | query

List of Object Identifiers (ZIDs) to fetch, separated by pipes. For example: zids=Z1|Z2|Z3
revisions

optional | query

List of Revision IDs for each of the specified Object ZID. If unset, the endpoint will return the latest revision. There should be the same number of Revision IDs as Object ZIDs, or none at all. For example: revisions=100|101|102
language

optional | query

Language code to return the Object labels in. For example: ar (Arabic), en (English), es (Spanish). List supported languages.

Responses

[edit]
200 Success Object found. Returns the encoded JSON value of the requested object.
Example
{
  "Z111": {
    "wikilambda_fetch": "{\n    \"Z1K1\": \"Z2\",\n    \"Z2K1\": \"Z111\"\n}"
  },
  "Z112": {
    "wikilambda_fetch": "{\n    \"Z1K1\": \"Z2\",\n    \"Z2K1\": \"Z112\"\n}"
  }
}
400 Z500: Error The number of Object IDs in the zids parameter doesn't match the number of requested Revision IDs.
Example
{
    "error": {
        "code": "wikilambda-zerror",
        "info": "Error of type Z500",
        "message": "Unspecified error",
        "zerror": {
            "Z1K1": "Z5",
            "Z5K1": "Z500",
            "Z5K2": {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z885",
                    "Z885K1": "Z500"
                },
                "K1": "You must specify a revision for each ZID, or none at all."
            }
        },
        "labelled": {
            "type": "Error",
            "error type": "Unspecified error",
            "error value": {
                "type": {
                    "type": "Function call",
                    "function": "Errortype to type",
                    "errortype": "Unspecified error"
                },
                "error information": "You must specify a revision for each ZID, or none at all."
            }
        }
    }
}
404 Z549: Invalid reference The zids parameter contains one or more invalid Object references. A valid Object reference must be a number prefixed by Z.
Example
{
    "error": {
        "code": "wikilambda-zerror",
        "info": "Error of type Z549",
        "message": "Invalid reference",
        "zerror": {
            "Z1K1": "Z5",
            "Z5K1": "Z549",
            "Z5K2": {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z885",
                    "Z885K1": "Z549"
                },
                "K1": "BAD REFERENCE"
            }
        },
        "labelled": {
            "type": "Error",
            "error type": "Invalid reference",
            "error value": {
                "type": {
                    "type": "Function call",
                    "function": "Errortype to type",
                    "errortype": "Invalid reference"
                },
                "reference value": "BAD REFERENCE"
            }
        }
    }
}
404 Z550: Unknown reference One or more of the Object references passed in the parameter parameters zids could not be found.
Example
{
    "error": {
        "code": "wikilambda-zerror",
        "info": "Error of type Z550",
        "message": "Unknown reference",
        "zerror": {
            "Z1K1": "Z5",
            "Z5K1": "Z550",
            "Z5K2": {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z885",
                    "Z885K1": "Z550"
                },
                "K1": {
                    "Z1K1": "Z6",
                    "Z6K1": "Z1000"
                }
            }
        },
        "labelled": {
            "type": "Error",
            "error type": "Unknown reference",
            "error value": {
                "type": {
                    "type": "Function call",
                    "function": "Errortype to type",
                    "errortype": "Unknown reference"
                },
                "reference value": {
                    "type": "String",
                    "value": "Z1000"
                }
            }
        }
    }
}

Run function

[edit]
Method
GET
Path
www.wikifunctions.org/w/api.php?action=wikifunctions_run&format=json&function_call={ url_encoded_json_function

Runs a Function Call in the Wikifunctions orchestration service and returns the response. The Function Call must be formed following the Wikifunctions Function model specifications. See Z7/Function calls section for more details.

For example, the following JSON represents a Function Call to the function Join strings with the input strings "hello, " and "world!":

{
    "Z1K1": "Z7",
    "Z7K1": "Z10000",
    "Z10000K1": "hello, ",
    "Z10000K2": "world!"
}

The API returns an Object of type Z22/Evaluation result.

An Evaluation result object contains two important fields:

  • Z22K1/Response: Contains the output object that resulted from the execution of the given Function Call, if successful. If the evaluation failed, it contains Z24/Void.
  • Z22K2/Metadata: Contains a Map object with a collection of key-values that contain information about the evaluation. The keys can contain information about errors, implementation, programming language and version, duration, CPU usage or memory. For a detailed reference of all the possible metadata keys available, see the metadata documentation.

Here's an example of a successful Evaluation result object which returns one metadata key-value: orchestrationDuration:

{
    "Z1K1": "Z22",
    "Z22K1": "hello, world!",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "orchestrationDuration",
                "K2": "233 ms"
            }
        ]
    }
}

Model documentation

[edit]

Examples

[edit]

curl

[edit]
# Run the Function call Join with the inputs "hello, " and "world!",
# which is represented by the following JSON object:
# {
#    "Z1K1": "Z7",
#    "Z7K1": "Z10000",
#    "Z10000K1": "hello, ",
#    "Z10000K2": "world!" 
# }

$ curl -G https://www.wikifunctions.org/w/api.php \
   --data-urlencode 'action=wikifunctions_run' \
   --data-urlencode 'format=json' \
   --data-urlencode 'formatversion=2' \
   --data-urlencode 'function_call={ "Z1K1": "Z7", "Z7K1": "Z10000", "Z10000K1": "hello, ", "Z10000K2": "world!" }'

Python

[edit]
# Python 3
# Run the Function call Join with the inputs "hello, " and "world!",
# which is represented by the following JSON object:
# {
#    "Z1K1": "Z7",
#    "Z7K1": "Z10000",
#    "Z10000K1": "hello, ",
#    "Z10000K2": "world!" 
# }

import requests

function_call = '{ "Z1K1": "Z7", "Z7K1": "Z10000", "Z10000K1": "hello, ", "Z10000K2": "world!" }'

url = 'https://www.wikifunctions.org/w/api.php'
params = {
    "action": "wikifunctions_run",
    "format": "json",
    "formatversion": "2",
    "function_call": function_call
} 

response = requests.get(url, params)
data = response.json()
print(data)

PHP

[edit]
<?php
/*
 * Run the Function call Join with the inputs "hello, " and "world!",
 * which is represented by the following JSON object:
 * {
 *    "Z1K1": "Z7",
 *    "Z7K1": "Z10000",
 *    "Z10000K1": "hello, ",
 *    "Z10000K2": "world!" 
 * }
 */

$function_call = '{"Z1K1": "Z7", "Z7K1": "Z10000", "Z10000K1": "hello, ", "Z10000K2": "world!" }';

$url = 'https://www.wikifunctions.org/w/api.php?action=wikifunctions_run&format=json&formatversion=2&function_call=' . urlencode( $function_call );

$ch = curl_init( $url );
$output = curl_exec( $ch );
curl_close( $ch );

echo( $output );
?>

JavaScript

[edit]
/*
Run the Function call Join with the inputs "hello, " and "world!",
which is represented by the following JSON object:
{
  "Z1K1": "Z7",
  "Z7K1": "Z10000",
  "Z10000K1": "hello, ",
  "Z10000K2": "world!" 
}
*/

let function_call = {
  "Z1K1": "Z7",
  "Z7K1": "Z10000",
  "Z10000K1": "hello, ",
  "Z10000K2": "world!" 
};
let url = 'https://www.wikifunctions.org/w/api.php?action=wikifunctions_run&format=json&formatversion=2&function_call=' + encodeURI( function_call );

let response = await fetch( url );
response.json()
    .then(console.log)
    .catch(console.error);

Parameters

[edit]
function_call

required | query

URL-encoded JSON representation of the Function Call to send for execution. For example:
{
   "Z1K1":"Z7",
   "Z7K1":"Z801",
   "Z801K1":"some text"
}

Responses

[edit]
200 Success The Function Call was executed successfully. Returns a Result Envelope containing the return value and a map of Metadata objects.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "output object!",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "orchestrationMemoryUsage",
                "K2": "108.84 MiB"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "orchestrationCpuUsage",
                "K2": "173.821 ms"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "orchestrationDuration",
                "K2": "139 ms"
            }
        ]
    }
}
403 Z559: User not permitted to run Function The user does not have the necessary rights to run a Function Call. For more details see User groups at Wikifunctions.
Example
{
    "error": {
        "code": "wikilambda-zerror",
        "info": "Error of type Z559",
        "message": "User not permitted to evaluate function",
        "zerror": {
            "Z1K1": "Z5",
            "Z5K1": "Z559",
            "Z5K2": {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z885",
                    "Z885K1": "Z559"
                }
            }
        },
        "labelled": {
            "type": "Error",
            "error type": "User not permitted to evaluate function",
            "error value": {
                "type": {
                    "type": "Function call",
                    "function": "Errortype to type",
                    "errortype": "User not permitted to evaluate function"
                }
            }
        }
    }
}
429 Too many requests The limit of concurrent calls has been reached.
Example
{
    "error": {
        "code": "wikilambda_function_call-concurrency-limit",
        "info": "You have too many function calls executing right now."
    }
}
503 Connection error Unable to connect to the Function Orchestrator service.
Example
{
    "error": {
        "code": "wikilambda_function_call-not-connected",
        "info": "Could not resolve host 'http://core-function-orchestrator-1:6254/1/v1/evaluate', probably because the orchestrator is not running. Please consult the README to add the orchestrator to your docker-compose configuration."
    }
}
200 Z502: Validation error The given Function Call is not well formed. The error body will contain the nested sub-errors that better describe the problem. For more information about nesting of validation error, read the Representation of errors page in meta.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z502",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z502"
                        },
                        "Z502K1": "Z523",
                        "Z502K2": {
                            "Z1K1": "Z5",
                            "Z5K1": "Z523",
                            "Z5K2": {
                                "Z1K1": {
                                    "Z1K1": "Z7",
                                    "Z7K1": "Z885",
                                    "Z885K1": "Z523"
                                },
                                "Z523K1": {
                                    "Z1K1": "Z99",
                                    "Z99K1": {
                                        "Z7K1": "Z801",
                                        "Z801": "some input"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        ]
    }
}
200 Z504: Zid not found One of the ZIDs mentioned in the Function Call object cannot be found.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z504",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z504"
                        },
                        "Z504K1": {
                            "Z1K1": "Z6",
                            "Z6K1": "Z1000000"
                        }
                    }
                }
            }
        ]
    }
}
200 Z506: Argument type mismatch The type of an argument instantiated in the Function Call does not match with its function argument definition.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z506",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z506"
                        },
                        "Z506K1": "Z40",
                        "Z506K2": {
                            "Z1K1": "Z6",
                            "Z6K1": "Z6"
                        },
                        "Z506K3": "wrong argument type",
                        "Z506K4": {
                            "Z1K1": "Z5",
                            "Z5K1": "Z542",
                            "Z5K2": {
                                "Z1K1": {
                                    "Z1K1": "Z7",
                                    "Z7K1": "Z885",
                                    "Z885K1": "Z542"
                                },
                                "Z542K1": "Z40",
                                "Z542K2": "Z6"
                            }
                        }
                    }
                }
            }
        ]
    }
}
200 Z507: Error in evaluation Something happened during the execution step which raised an error. The returned value of this error will also include the error propagated from the function evaluator and/or executor services.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z507",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z507"
                        },
                        "Z507K1": {
                            "Z1K1": "Z99",
                            "Z99K1": {
                                "Z1K1": {
                                    "Z1K1": "Z9",
                                    "Z9K1": "Z7"
                                },
                                "Z7K1": {
                                    "Z1K1": "Z9",
                                    "Z9K1": "Z802"
                                },
                                "Z802K1": {
                                    "Z1K1": "Z9",
                                    "Z9K1": "Z42"
                                }
                            }
                        },
                        "Z507K2": {
                            "Z1K1": "Z5",
                            "Z5K1": "Z511",
                            "Z5K2": {
                                "Z1K1": {
                                    "Z1K1": "Z7",
                                    "Z7K1": "Z885",
                                    "Z885K1": "Z511"
                                },
                                "Z511K1": {
                                    "Z1K1": "Z39",
                                    "Z39K1": "Z802K2"
                                },
                                "Z511K2": {
                                    "Z1K1": "Z99",
                                    "Z99K1": {
                                        "Z1K1": {
                                            "Z1K1": "Z9",
                                            "Z9K1": "Z7"
                                        },
                                        "Z7K1": {
                                            "Z1K1": "Z9",
                                            "Z9K1": "Z802"
                                        },
                                        "Z802K1": {
                                            "Z1K1": "Z9",
                                            "Z9K1": "Z42"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        ]
    }
}
200 Z516: Argument value error One of the arguments passed to a built-in Function had a wrong value or type.
200 Z517: Return type mismatch The type returned by a Function Call does not match the expected type from that function definition.
200 Z518: Object type mismatch The Object sent for evaluation is not a Function Call, or one of its arguments cannot be processed or their type evaluated.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z518",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z518"
                        },
                        "Z518K1": "Z7",
                        "Z518K2": "not a function call",
                        "Z518K3": {
                            "Z1K1": "Z5",
                            "Z5K1": "Z502",
                            "Z5K2": {
                                "Z1K1": {
                                    "Z1K1": "Z7",
                                    "Z7K1": "Z885",
                                    "Z885K1": "Z502"
                                },
                                "Z502K1": "Z511",
                                "Z502K2": {
                                    "Z1K1": "Z5",
                                    "Z5K1": "Z511",
                                    "Z5K2": {
                                        "Z1K1": {
                                            "Z1K1": "Z7",
                                            "Z7K1": "Z885",
                                            "Z885K1": "Z511"
                                        },
                                        "Z511K1": {
                                            "Z1K1": "Z39",
                                            "Z39K1": "Z7K1"
                                        },
                                        "Z511K2": {
                                            "Z1K1": "Z99",
                                            "Z99K1": {
                                                "Z1K1": "Z6",
                                                "Z6K1": "not a function call"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        ]
    }
}
200 Z542: Unexpected Object type An Object passed as an Argument has an unexpected type.
Example
{
    "Z1K1": "Z22",
    "Z22K1": "Z24",
    "Z22K2": {
        "Z1K1": {
            "Z1K1": "Z7",
            "Z7K1": "Z883",
            "Z883K1": "Z6",
            "Z883K2": "Z1"
        },
        "K1": [
            {
                "Z1K1": "Z7",
                "Z7K1": "Z882",
                "Z882K1": "Z6",
                "Z882K2": "Z1"
            },
            {
                "Z1K1": {
                    "Z1K1": "Z7",
                    "Z7K1": "Z882",
                    "Z882K1": "Z6",
                    "Z882K2": "Z1"
                },
                "K1": "errors",
                "K2": {
                    "Z1K1": "Z5",
                    "Z5K1": "Z506",
                    "Z5K2": {
                        "Z1K1": {
                            "Z1K1": "Z7",
                            "Z7K1": "Z885",
                            "Z885K1": "Z506"
                        },
                        "Z506K1": "Z40",
                        "Z506K2": {
                            "Z1K1": "Z6",
                            "Z6K1": "Z6"
                        },
                        "Z506K3": "wrong argument type",
                        "Z506K4": {
                            "Z1K1": "Z5",
                            "Z5K1": "Z542",
                            "Z5K2": {
                                "Z1K1": {
                                    "Z1K1": "Z7",
                                    "Z7K1": "Z885",
                                    "Z885K1": "Z542"
                                },
                                "Z542K1": "Z40",
                                "Z542K2": "Z6"
                            }
                        }
                    }
                }
            }
        ]
    }
}

Report a bug

[edit]

Create an account on Wikimedia Phabricator, and tag the task with Wikifunctions.

Get help

[edit]

Leave a comment on the Wikifunctions project chat.

Changelog

[edit]

See Wikimedia APIs/Changelog.

About this page

[edit]

This page was adapted from the Wikimedia API Portal by Geno (WMF), Ameisenigel, Jdforrester (WMF), and APaskulin (WMF), licensed under CC BY-SA 4.0. The content has been modified for use on mediawiki.org.