Generate a local REST reference
The REST documentation on the Magento devdocs website is generated with Swagger UI using a schema derived from the latest build of Magento 2. However, the REST API documentation on devdocs is static in that the Magento Developers website is not running an instance of Magento, and there is no live data.
Magento provides two ways to get detailed information about the structure of the REST endpoints, as described below.
Generate a full REST reference locally
The Swagger UI is installed automatically on your server. As a result, you can generate live REST API documentation that can include Magento Commerce modules, third-party modules, and extension attributes that have been installed on your system. To view this documentation, go to:
http://<magento_host>/swagger
To view the Swagger documentation for a specific store view, use this URL:
http://<magento_host>/swagger?store=<store_code>
The value of store_code
must be one of the following:
default
- The assigned store code
all
. This value only applies to the CMS and Product modules. If this value is specified, the API call affects all the merchant’s stores.
By default, Magento returns documentation for resources available to anonymous users across all stores. If you specify a valid value in the api_key
text box in the upper right corner, Swagger returns documentation for all the endpoints the user has access to. To generate an API key, call the POST /V1/integration/customer/token
or POST /V1/integration/admin/token
as directed in Token-based authentication.
The generated Swagger documentation provides the capability to test REST requests. A user can enter a sample request, then press the Try it out! button, and Swagger returns information such as a curl
command, a request URL, a response body, a response code, and the response header. The Try it out! button will not work unless a bearer authorization token has been specified.
The Try it out! feature is not available on Swagger documentation published on the Magento devdocs website.
Return the JSON schema for one or more services
You can use a REST client to generate the JSON schema for one or more services. In the client, set the method to GET
and the URL to
http://<magento_host>/rest/<store_code>/schema?services=<serviceName1,serviceName2,..>
For example:
http://<magento_host>/rest/default/schema?services=catalogProductRepositoryV1
To return information about all services:
http://<magento_host>/rest/<store_code>/schema
You must specify an authorization token for an admin user to return information for most endpoints. See Token-based authentication for more information.
Return the complete JSON schema
To return the complete JSON schema, specify the ?services=all
parameter in the URL. The default store_code
is all
, but you can also specify default
or a store code defined on the system. For example: http://<magento_host>/rest/default/schema?services=all