Create a Perfect Website

Webiny API documentation

What is Webiny API

Webiny API is a set of functions whose aim is to help you obtain any data regarding your Webiny account. A common usage is to get site settings, a list of pages filtered by certain criteria, and so on.

 

Webiny API functions are categorized into several logical sections:

How to use Webiny API functions

There are two different ways you can call an API function. The method you need to use depends on if you are calling the API function from within a TPL (template) file, or from a PHP file.

TPL file

Calling an API function from a template file is quite easy, just put the API function call anywhere inside your template. Here is an example how an API call is formed inside a template file: 

{api_call function="api_function_name" params="parameters" var="result"}

PHP file

If your PHP file is a part of your theme, then use the following method:

$apiCall = array
(
	'function'	=> 'api_function_name',
	'params'	=> array($param1, $param2, ...),
	'explode'	=> true // optional parameter -> required only for some API functions
);

$result = Webiny_Theme_API::api_call($apiCall);

If your file is a part of some custom module, than you can just create a new instance of Webiny_API and call returnApi method. Here is an example:

$coreAPI = Webiny_Frontend_Core::getApi();					// the best way to get the core api
$businessAPI = $coreAPI->returnAPI('business');				// from core api you get get instance of any other api
$businessAPI->api_function_name($param1, $param2, ...);		// when you have an api instance, just call an api function like if it's a normal method
APIs' are like classes, so you can also extend them with your custom classes.

How to register a custom API function

Registering custom API functions from within a Webiny theme requires a few steps:

  1. Create a php file inside your theme folder. You can name it anyway you want.
  2. Define your function within that file, just make sure the function name starts with a prefix 'wtapi_' (short for Webiny Theme API).
  3. Include that PHP file inside your tpl file by calling {api_call function="open_file" params="path=my_file.php"}
  4. Use {api_call} anywhere you want within that file to call your function.

See also

How to create a Webiny theme
Theme data & variables
Core API
Webiny Q&A Board - if you would need any help

Search API

Webiny API documentation