Wie aktiviere ich den Zugriff auf die Shopware 6 API? (Self-Hosted) No route found Error

Hallo zusammen, ich muss für einen Kunden eine Schnittstelle einbinden. Diese soll natürlich über die Shopware 6 API laufen.

Wenn ich nun allerdings die URL https://mein-shop.de/api/ aufrufe bekomme ich folgende Fehlermeldung:

 {"errors":[{"code":"0","status":"404","title":"Not Found","detail":"No route found for \u0022GET \/api\/\u0022","meta":....}

Weiss jemand woran das liegen kann? In der .env Datei ist der Modus „dev“ eingetragen.

Mit freundlichen Grüßen 

 

Afaik musst du da garnix aktivieren. Die Api ist immer da.

Anmelden kannst du dich z.B. mit dem User.

Probier doch mal den Link, da sollte dann denied kommen: https://www.mein-shop.de/api/v3/product

@ThomasChr schrieb:

Afaik musst du da garnix aktivieren. Die Api ist immer da.

Anmelden kannst du dich z.B. mit dem User.

Probier doch mal den Link, da sollte dann denied kommen: https://www.mein-shop.de/api/v3/product

Folgendes bekomme ich ausgegeben:

{“errors”:[{“code”:“9”,“status”:“401”,“title”:“The resource owner or authorization server denied the request.”,“detail”:“Missing \u0022Authorization\u0022 header”,“meta”:{“trace”:[{“file”:"/home/default/html/vendor/league/oauth2-server/src/AuthorizationValidators/BearerTokenValidator.php",“line”:62,“function”:“accessDenied”,“class”:“League\OAuth2\Server\Exception\OAuthServerException”,“type”:"::",“args”:[“Missing \u0022Authorization\u0022 header”]},{“file”:"/home/default/html/vendor/league/oauth2-server/src/ResourceServer.php",“line”:84,“function”:“validateAuthorization”,“class”:“League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator”,“type”:"-\u003E",“args”:[{}]},{“file”:"/home/default/html/vendor/shopware/core/Framework/Api/EventListener/Authentication/ApiAuthenticationListener.php",“line”:117,“function”:“validateAuthenticatedRequest”,“class”:“League\OAuth2\Server\ResourceServer”,“type”:"-\u003E",“args”:[{}]},{“file”:"/home/default/html/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",“line”:126,“function”:“validateRequest”,“class”:“Shopware\Core\Framework\Api\EventListener\Authentication\ApiAuthenticationListener”,“type”:"-\u003E",“args”:[{},“kernel.controller”,{}]},{“file”:"/home/default/html/vendor/symfony/event-dispatcher/EventDispatcher.php",“line”:264,“function”:"__invoke",“class”:“Symfony\Component\EventDispatcher\Debug\WrappedListener”,“type”:"-\u003E",“args”:[{},“kernel.controller”,{}]},{“file”:"/home/default/html/vendor/symfony/event-dispatcher/EventDispatcher.php",“line”:239,“function”:“doDispatch”,“class”:“Symfony\Component\EventDispatcher\EventDispatcher”,“type”:"-\u003E",“args”:[[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}],“kernel.controller”,{}]},{“file”:"/home/default/html/vendor/symfony/event-dispatcher/EventDispatcher.php",“line”:73,“function”:“callListeners”,“class”:“Symfony\Component\EventDispatcher\EventDispatcher”,“type”:"-\u003E",“args”:[[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}],“kernel.controller”,{}]},{“file”:"/home/default/html/vendor/shopware/core/Framework/Webhook/WebhookDispatcher.php",“line”:88,“function”:“dispatch”,“class”:“Symfony\Component\EventDispatcher\EventDispatcher”,“type”:"-\u003E",“args”:[{},“kernel.controller”]},{“file”:"/home/default/html/vendor/shopware/core/Framework/Event/BusinessEventDispatcher.php",“line”:46,“function”:“dispatch”,“class”:“Shopware\Core\Framework\Webhook\WebhookDispatcher”,“type”:"-\u003E",“args”:[{},“kernel.controller”]},{“file”:"/home/default/html/vendor/shopware/core/Framework/Event/NestedEventDispatcher.php",“line”:32,“function”:“dispatch”,“class”:“Shopware\Core\Framework\Event\BusinessEventDispatcher”,“type”:"-\u003E",“args”:[{},“kernel.controller”]},{“file”:"/home/default/html/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",“line”:168,“function”:“dispatch”,“class”:“Shopware\Core\Framework\Event\NestedEventDispatcher”,“type”:"-\u003E",“args”:[{},“kernel.controller”]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpKernel.php",“line”:146,“function”:“dispatch”,“class”:“Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher”,“type”:"-\u003E",“args”:[{},“kernel.controller”]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpKernel.php",“line”:80,“function”:“handleRaw”,“class”:“Symfony\Component\HttpKernel\HttpKernel”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1]},{“file”:"/home/default/html/vendor/symfony/http-kernel/Kernel.php",“line”:201,“function”:“handle”,“class”:“Symfony\Component\HttpKernel\HttpKernel”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1,true]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpCache/SubRequestHandler.php",“line”:85,“function”:“handle”,“class”:“Symfony\Component\HttpKernel\Kernel”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1,true]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpCache/HttpCache.php",“line”:477,“function”:“handle”,“class”:“Symfony\Component\HttpKernel\HttpCache\SubRequestHandler”,“type”:"::",“args”:[{},{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1,true]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpCache/HttpCache.php",“line”:450,“function”:“forward”,“class”:“Symfony\Component\HttpKernel\HttpCache\HttpCache”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},true]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpCache/HttpCache.php",“line”:344,“function”:“fetch”,“class”:“Symfony\Component\HttpKernel\HttpCache\HttpCache”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},true]},{“file”:"/home/default/html/vendor/symfony/http-kernel/HttpCache/HttpCache.php",“line”:222,“function”:“lookup”,“class”:“Symfony\Component\HttpKernel\HttpCache\HttpCache”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},true]},{“file”:"/home/default/html/vendor/shopware/core/HttpKernel.php",“line”:163,“function”:“handle”,“class”:“Symfony\Component\HttpKernel\HttpCache\HttpCache”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1,true]},{“file”:"/home/default/html/vendor/shopware/core/HttpKernel.php",“line”:80,“function”:“doHandle”,“class”:“Shopware\Core\HttpKernel”,“type”:"-\u003E",“args”:[{“attributes”:{},“request”:{},“query”:{},“server”:{},“files”:{},“cookies”:{},“headers”:{}},1,true]},…

Das heißt die API ist da!

Ich kann hier nur mit Python dienen, aber mach halt das mal:

import json
import requests

url = 'https://www.mein-shop.de'
userid = 'xxx'
userpass = 'yyy'

artnr = '123'

##### LOGIN #####
requrl = url + '/api/oauth/token'
payload = {'client_id': 'administration', 'grant_type': 'password', 'scopes': 'write', 'username': userid, 'password': userpass}
r = requests.post(requrl, json=payload)
r = json.loads(r.text)
token = r['access_token']

##### GET PRODUCT_BY_ARTNR #####
requrl = url + '/api/v3/product' + '?filter[product.productNumber]=' + artnr
headers = {'Accept': 'application/json', 'Authorization' : 'Bearer ' + token}
r = requests.get(requrl, headers=headers)
r = json.loads(r.text)
productid = r['data'][0]['_uniqueIdentifier']

 

@ThomasChr schrieb:

Das heißt die API ist da!

Ich kann hier nur mit Python dienen, aber mach halt das mal:

import json
import requests

url = 'https://www.mein-shop.de'
userid = 'xxx'
userpass = 'yyy'

artnr = '123'

##### LOGIN #####
requrl = url + '/api/oauth/token'
payload = {'client_id': 'administration', 'grant_type': 'password', 'scopes': 'write', 'username': userid, 'password': userpass}
r = requests.post(requrl, json=payload)
r = json.loads(r.text)
token = r['access_token']

##### GET PRODUCT_BY_ARTNR #####
requrl = url + '/api/v3/product' + '?filter[product.productNumber]=' + artnr
headers = {'Accept': 'application/json', 'Authorization' : 'Bearer ' + token}
r = requests.get(requrl, headers=headers)
r = json.loads(r.text)
productid = r['data'][0]['_uniqueIdentifier']

 

Super, vielen vielen Dank!

Das hat perfekt geklappt.

1 Like