Hey i want to use the shopware 6 api to fill my store with products. Sadly i cant get from reading the documentation on how to use the api in python. Im talking about this https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTUy-product-data where a payload is specified, but i cant get from the doc on how to authenticate on python or how to post the payload.
Asked
Active
Viewed 273 times
0
-
5There's a section on authentication: https://shopware.stoplight.io/docs/admin-api/ZG9jOjEwODA3NjQx-authentication. There's a section on Request & Response Structure: https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzAzNDU1-request-and-response-structure. Then search for "making requests to APIs using python", which will lead to results like this: https://stackoverflow.com/q/17301938/2745495 – Gino Mempin Jun 26 '22 at 13:41
-
1There is a third-party community library that I haven't tried or verified personally, but it looks quite promising and has extensive documentation. Maybe worth having a look - https://github.com/bitranox/lib_shopware6_api_base. – Dominic Klein Aug 10 '22 at 16:00
1 Answers
0
For my personal use I have created a very simple Python abstraction for the Shopware API, find it here: https://github.com/aragon999/python-shopware/ Note there is currently no installer or anything, I might add something in the future.
I will quickly outline the most important steps for authentication using API credentials. For simplicity assume we have a method unauthenticated_call()
which does an non authenticated call to the Shopware API:
- First you should obtain the bearer-token using an API request to
oauth/token
:unauthenticated_call("oauth/token", fields={ "grant_type": "client_credentials", "client_id": self.key_id, "client_secret": self.key_secret, })["access_token"]
- Now add to any API call which should be authenticated (using the
access_token
obtained in the previous step):{ "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", "Accept": "application/vnd.api+json", }
- The token bearer token itself is only valid for 10 minutes, once it is not valid anymore the API will respond with status
401
, when this happens you should create a new token. For password authentication you should use therefresh_token
.

aragon999
- 126
- 4