# Login as guest with store-api

**URL:** <https://forum.shopware.com/t/login-as-guest-with-store-api/95213>\
**Category:** Shopware 6 (English)\
**Tags:** programming\
**Created:** [9. Juli 2022 um 16:43 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213 "2022-07-09T16:43:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![martineichinger](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@martineichinger](https://forum.shopware.com/u/martineichinger)\
**Post date:** [9. Juli 2022 um 16:43 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/1 "2022-07-09T16:43:41Z")

</div>

When I do the user registration via the store-api as a guest:

> [https://my-url.com/store-api/account/register](https://my-url.com/store-api/account/register)

I cannot login via

> [https://my-url.com/store-api/account/login](https://my-url.com/store-api/account/login)

with following error message:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/8/2/82fdec4d9c17ee2f5b801a83d8e220808c813764.png)

When I do exactly the same, but not as a guest, it works. That means I register with the same body data besides „guest“: true (which I deleted in the body).

Any suggestions what might be wrong, when registering as a guest.

I use shopware 6.4.13.

---

<div class="post-metadata">

**Author:** ![mhdalalwan](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mhdalalwan](https://forum.shopware.com/u/mhdalalwan)\
**Post date:** [26. Juli 2022 um 18:29 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/2 "2022-07-26T18:29:15Z")

</div>

Were you able to find out how to login as guest?

---

<div class="post-metadata">

**Author:** ![martineichinger](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@martineichinger](https://forum.shopware.com/u/martineichinger)\
**Post date:** [5. August 2022 um 06:12 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/3 "2022-08-05T06:12:57Z")

</div>

No unfortunately not.

---

<div class="post-metadata">

**Author:** ![ws2](https://avatars.discourse-cdn.com/v4/letter/w/2bfe46/32.png) [@ws2](https://forum.shopware.com/u/ws2)\
**Post date:** [3. Oktober 2022 um 14:57 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/4 "2022-10-03T14:57:23Z")

</div>

[https://www.YourURL.com/account/guest/login](https://www.YourURL.com/account/guest/login)  
Hope this can help you. It is impossible to find…  
But it seems, that it not work for itself.  
Our shop sending a special link with an special order ID like this:  
[https://www.YourURL.com/account/guest/login?redirectTo=frontend.account.order.single.page&redirectParameters[deepLinkCode]=1234567890&loginError=0&waitTime=](https://www.YourURL.com/account/guest/login?redirectTo=frontend.account.order.single.page&redirectParameters%5BdeepLinkCode%5D=1234567890&loginError=0&waitTime=)

I have replaced the order code that our shop generated with 1234567890.

---

<div class="post-metadata">

**Author:** ![Gendai](https://avatars.discourse-cdn.com/v4/letter/g/a9a28c/32.png) [@Gendai](https://forum.shopware.com/u/Gendai)\
**Post date:** [3. Oktober 2022 um 17:02 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/5 "2022-10-03T17:02:04Z")

</div>

perhaps this helps

> <https://github.com/shopware/platform/pull/2701>
>
> \<!--
> Thank you for contributing to Shopware! Please fill out this description t…emplate to help us to process your pull request.
> 
> Please make sure to fulfil our contribution guideline (https://developer.shopware.com/docs/resources/guidelines/code/contribution?category=shopware-platform-dev-en/contribution).
> 
> Do your changes need to be mentioned in the documentation?
> Please create a second pull request at https://github.com/shopware/docs
> \--\>
> 
> \### 1. Why is this change necessary?
> Currently it is not possible to login as customer from administration
> 
> \### 2. What does this change do, exactly?
> Adds a new button "Login as customer" next to "Edit" after clicking the button a modal with sales channels list will be shown.
> Token will be generated to ensure not everyone can guess the token, the token will be validated on the storefront & store api side as well.
> 
> !\[Bildschirmfoto 2022-09-24 um 00 27 24\](https://user-images.githubusercontent.com/27974830/192064928-961dc566-b0ae-43a9-8480-98d80e32b037.png)
> 
> !\[Bildschirmfoto 2022-09-28 um 00 03 02\](https://user-images.githubusercontent.com/27974830/192645712-bf4d9f69-532c-43bb-961b-8a2974bed195.png)
> 
> \### 3. Describe each step to reproduce the issue or behaviour.
> Administration -\> Customers -\> Overview select a customer after clicking on "Login as customer" you should see a modal "Select the sales channel below you wish to perform the login". 
> Click on the sales channel you like and you should be redirected to the storefront like you would normal login.
> Cart and Context should be restored.
> 
> \### 4. Please link to the relevant issues (if any).
> \[https://github.com/shopware/platform/pull/1572\](https://github.com/shopware/platform/pull/1572)
> \[https://github.com/shopware/platform/issues/878\](https://github.com/shopware/platform/issues/878)
> 
> \### 5. Checklist
> 
> \- \[\] I have rebased my changes to remove merge conflicts
> \- \[x\] I have written tests and verified that they fail without my change
> \- \[x\] I have created a \[changelog file\](https://github.com/shopware/platform/blob/trunk/adr/workflow/2020-08-03-implement-New-Changelog.md) with all necessary information about my changes
> \- \[x\] I have written or adjusted the documentation according to my changes
> \- \[x\] This change has comments for package types, values, functions, and non-obvious lines of code
> \- \[x\] I have read the contribution requirements and fulfil them.

---

<div class="post-metadata">

**Author:** ![FritzPerson](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@FritzPerson](https://forum.shopware.com/u/FritzPerson)\
**Post date:** [8. August 2023 um 06:00 UTC](https://forum.shopware.com/t/login-as-guest-with-store-api/95213/6 "2023-08-08T06:00:37Z")

</div>

I’m replying to this topic, because I had the same problem, and so it might be useful for people who find this forum post in the future.

A guest can’t be logged in BUT if you make the API-requests in the right order, the guest will count as „logged-in“ upon registration for the checkout step.

The right order here means creating a cart before registering a guest: (only listing the API endpoints)

1. /store-api/context – use this token until step (5)
2. /store-api/checkout/cart
3. /store-api/checkout/cart/line-item
4. /store-api/account/register – the response header will contain a new sw-context-token
5. /store-api/checkout/order – using the new token

For the requests you can use the data from the Store-API quick guide: [Registering a customer | Store API (stoplight.io)](https://shopware.stoplight.io/docs/store-api/aa7ea5e14dea6-registering-a-customer)  
But add `"guest": true` for the /store-api/account/register call.
