Shopware 6 and Paw

If you prefer Postman, Matthias Zeis wrote about it!

I’m just writing a little plugin and for some reason the API is not returning the seo_urls on a product – once I fiddled out the reason for that hopefully I write another blog post.

But for the moment I need to debug the Shopware 6 API and the result. Copying over the API call from Safaris Network tab as cURL and calling it again and again on the console (to not mix it up with all the other AJAX calls, especially the message queue consume, etc.) is a little annoying, because if you take too long this happens:

{
   "errors":[
      {
         "code":"9",
         "status":"401",
         "title":"The resource owner or authorization server denied the request.",
         "detail":"Access token could not be verified",
         "meta":{
            "trace":[
                [...]
            ],
            "file":"\/var\/www\/html\/vendor\/league\/oauth2-server\/src\/Exception\/OAuthServerException.php",
            "line":243
         }
      }
   ]
}

So to make it easier it would be cool to have a client which automatically takes care of Authorization and because I couldn’t find a blog post for me, here is one!

I’m using Paw. Paw is awesome and a lot of fun. You can do SO MUCH with it and I didn’t even touch the surface.

How to configure Shopware?

Create a Shopware Integration.

Settings > Integrations > New
Screenshot of Integrations admin area of Shopware 6, with an arrow pointing to the "Add integration" button
Manage Integrations in the admin area of Shopware 6

After clicking the button, you get the following form, enter the best name you can come up with, for testing purposes just use “Administration” as role, so you can do anything and copy Access key ID and Secret access key!

Important! The credentials only work if you click “Save integration”!

Screenshot of the "Create integration" form. A field with a name, a checkbox for "Administration" or a dropdown to choose a role. And a prefilled text field with access key id and secred access key. A warning: Please note down the access key now. After saving the integration, the key will no longer be visible, due to safety concerns.
And two buttons: "Cancel" and "Save integration"
Form to create new Integration credentials

If you don’t create the user locally and/or not for testing purposes, think extensively which access the user needs to give him as less permissions as possible.

Once this is done we can configure Paw!

How to configure Paw?

Create a new Paw project. Under Auth you find OAuth 2 and there you configure the following:

Screenshot of Paw with Auth > OAuth 2 open.
Grant Type: Client Credentials
Client ID: Access key ID
Client Secret: Secret access key
Checkboy for "Set client credentials in body" NOT checked
Access token URL: http://localhost/api/oauth/token
Scope: write
Paw: OAuth 2 configuration formO

Once configure (and assuming you saved the configuration on the shopware backend ;-)) you can now click on “Get Access Token” and you should be greeted by:

Paw Popup:
Access Token Granted
Access Token: long random string
Button: Cancel  and Use Access Token
Paw Popup with a successfully fetched access token

One click on Use Acccess Token and you can start using the API by entering it in the top field:

Paw: top form with url "http://localhost/api/search/product"

Hope it works for you!

Good luck and happy coding!

Leave a Reply