Shopware 6 API + NodeJs-quick guide
How to get started fetching data using Http based requests from Shopware 6 — NodeJs.
I DONT USE PHP.. Nowadays, Js is much more accessible for the average new-gen coder in a team that would be maintaining API integrations.
To be continued…
Before we get started
First of all, most Http requests against the Shopware API must be authorised, for example using the JWT (JSON Web token) “Bearer Token” schema. I would use that over an user-credential based authentication during development for ease of use to not having to authorise again every time. With JWT’s you can keep your access alive for a certain time-period.
How do we authorise ourselves? -sending a user-login or an integration access-key and access-key secret to the authentication endpoint to obtain a JWT access token. For production-ready use cases it might be interesting to know, that within the Shopware 6 admin panel settings, they suggest to use integrations.
Let’s get started 🚀👨🏼🚀
put on your helmet, its a “rocky road”
Get a Shopware “Access Key” & “Access Key Secret”
Important: Take note of the “Access Key Secret”, as it will only be shown once! You can view the “Access Key ID” any time after creation in the admin panel.
Thus, by opening our Shopware 6 admin panel, located at
https://<your-store-domain>/admin and creating a new integration within “settings > integrations”, you obtain the “Access Key ID” as well as the “Access Key Secret”.
Getting a JWT Access Token
Note how when making authentication calls to
api/v3/oauth/token) you use “client_id” and “client_secret”, synonymous with the newly created integration’s generated “access key” and “access key secret”!
We have access, finally, yeay! 🎉
Now, what info can we get, but more importantly, how? -You can query the api to basically get any piece of information you’d want or see in the web backend or similar. You can do sales-channel specific queries, mutate data for a product within a certain category or attributed with a tag, the limits are few in the “what” regard, but what about “how”?
Shopware 6 API Routes
There is a “Schema” you can fetch from your Shopware 6 instance, from
/api/v3/_info/entity-schema.json , which are supposed to give further details about everything, although I found them quite intransparent to understand, when between the very beginning and feeling ready to use them, while working with the API. Thus, I’ve put together a little gist:
STORY TO BE CONTINUED…