This article is a summary of problems that are reported frequently and the solutions to those problems.
If you receive errors with HTML instead of JSON (usually with a complete stacktrace) like this:
<br />
<b>Fatal error</b>: Uncaught Shopware\Components\Api\Exception\NotFoundException: Article by id 23213213 not found in /engine/Shopware/Components/Api/Resource/Article.php:155
Stack trace:
#0 /engine/Shopware/Controllers/Api/Articles.php(75): Shopware\Components\Api\Resource\Article->getOne('23213213', Array)
#1 /engine/Library/Enlight/Controller/Action.php(159): Shopware_Controllers_Api_Articles->getAction()
#2 /engine/Library/Enlight/Controller/Dispatcher/Default.php(523): Enlight_Controller_Action->dispatch('getAction')
#3 /engine/Library/Enlight/Controller/Front.php(223): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp))
#4 /engine/Shopware/Kernel.php(182): Enlight_Controller_Front->dispatch()
#5 / in <b>2/engine/Shopware/Components/Api/Resource/Article.php</b> on line <b>155</b><br />
This is a sign that the configs throwExceptions and noErrorHandler which are located in config.php are set to true.
Removing these entries or setting them to false should resolve this issue.
.htaccess file?You need to add an exception for the API route. Here is an example for the .htaccess file:
SetEnvIf Request_URI "(.*\/api((\/?$)|(\/.*$)))" ALLOW
Order Allow,Deny
Authtype Basic
AuthName "Shopware Testshop"
AuthUserFile /path/to/.htpasswd
require valid-user
Allow from env=ALLOW
Allow from env=REDIRECT_ALLOW
Satisfy any
# Rest of the shopware .htaccess
...
There are two ways to allow API dev tools to authenticate with the Shopware API:
To transmit a data to the API, select JSON (application/json) as Content-Type.