How can we help you today?

How to Enable the Magento 2 API

Created by: Rens Zuurbier

Modified on: Fri, 29 May, 2020 at 8:54 AM


To enable the Magento API, first create the correct users.

The Magento API is supposed to work out-of-the box on Hypernodes, but due to clean-url-rewrites sometimes the API does not work and returns a 404 error.
To resolve this issue, some additional configuration is required.

Use the following snippet and save it as /data/web/nginx/server.api to configure Nginx for routing all API requests to api.php:

location /api {
    allow 1.2.3.4;
    allow 2.3.4.5;
    deny all;
 
    rewrite ^/api/rest /api.php?type=rest last;
    rewrite ^/api/v2_soap /api.php?type=v2_soap last;
    rewrite ^/api/soap /api.php?type=soap last;
 
    location ~ \.php$ {
        echo_exec @phpfpm;
    }
}

NB: If you don’t want to update IP addresses in all config files with every change of IP address, you can choose to use include files.

R
Rens is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.