layout | title | github_link | shopware_version | indexed | tags | group | subgroup | menu_title | menu_order | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
default |
REST API - Frequently Asked Questions |
developers-guide/rest-api/faq/index.md |
true |
|
Developer Guides |
REST API |
REST API FAQ |
340 |
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.
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:
- API tools like Postman support the following URL schema: http://username:apikey@mydemoshop.com/api/ (if you experience any issues with Postman, try the Google Chrome version instead of the standalone version)
- Use the HTTP Basic authentication (introduced with Shopware 5.3.2)
To transmit a data to the API, select JSON (application/json) as Content-Type.