# How to implement a webhook endpoint in Shopware?

**URL:** https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504
**Category:** International (English Only)
**Tags:** programming
**Created:** [24. Juni 2017 um 19:58 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504 "2017-06-24T19:58:07Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)
#### Post date: [24. Juni 2017 um 19:58 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/1 "2017-06-24T19:58:07Z")

</div>

Im&nbsp;working on a Shopware plugin that needs to have an endpoint which can receive post requests from a webhook. I’ve tried to do this with a custom API endpoint&nbsp;but this means that the API credentials have to be sent through the callback url like so&nbsp; **http://:\<api\_key\>@mywebshop.com/api/custom\_endpoint\</api\_key\>**.This works fine when I’m testing the endpoint with Postman, but when using this with the actual webhook, the endpoint is never reached. Can somebody tell me what the cause of the issue could be? Another way to achieve the desired result would also be appreciated.

Thnx in advance!

---

<div class="post-metadata">

### Author: ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)
#### Post date: [25. Juni 2017 um 11:04 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/2 "2017-06-25T11:04:06Z")

</div>

> &nbsp;&nbsp;have to be sent&nbsp;through the callback url like so&nbsp;http://:@mywebshop.com/api/custom\_endpoint.

Nope. You can also use digest authentication. Then you don’t need to put username and password in the url.&nbsp;If that’s also not supported by your webhook you could go with a controller:

> **[Shopware controller](https://developers.shopware.com/developers-guide/controller/)**
>
> Shopware controller

But then everyone could access it without authentication unless you implement your own.

---

<div class="post-metadata">

### Author: ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)
#### Post date: [26. Juni 2017 um 11:30 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/3 "2017-06-26T11:30:43Z")

</div>

I ended up using a simple controller. thank you!

---

<div class="post-metadata">

### Author: ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)
#### Post date: [14. September 2018 um 11:34 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/4 "2018-09-14T11:34:07Z")

</div>

> [@mdnapo schrieb:](https://forum.shopware.com/profile/24914/mdnapo "mdnapo")
> 
> I ended up using a simple controller. thank you!

Hi mdnapo,

I’m also trying to use a controller as callback url for a webhook but its not working. Can you share your simple solution?

Thanks

Danny

---

<div class="post-metadata">

### Author: ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)
#### Post date: [19. September 2018 um 14:55 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/5 "2018-09-19T14:55:54Z")

</div>

Hello Danny Dan,

A bit of a late reaction, but this is the way I achieved the desired result.

I started off by creating a controller that extends Enlight\_Controller\_Action and implements CSRFWhitelistAware in the Controller/Frontend folder.

Then simply whitelist the actions you want to access publicly.

I hope this helps! 🙂

Greets,

Donny

---

<div class="post-metadata">

### Author: ![mdnapo](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mdnapo](https://forum.shopware.com/u/mdnapo)
#### Post date: [19. September 2018 um 15:11 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/6 "2018-09-19T15:11:42Z")

</div>

To elaborate a&nbsp;little further. Like Simkli mentioned, when creating callback urls in this manner you have to take care of security yourself!

So be sure to add your own security model (if necessary).

Below is an example for creating a callback url controller&nbsp;that&nbsp;is reachable like so, [https://yourdomain.com/webhooks/index](https://yourdomain.com/webhooks/index).

```
class Shopware_Controllers_Frontend_Webhooks extends Enlight_Controller_Action implements CSRFWhitelistAware
{
    public function getWhitelistedCSRFActions()
    {
        // Whitelist the action
        return ['index'];
    }

    public function indexAction()
    {
        // Your code here
        ...

        // Call exit() after you've echoed your response, otherwise the controller might try to return a view, which could lead to errors.
        exit();
    }
}

```

Have a&nbsp;nice evening!

Greets,

Donny

---

<div class="post-metadata">

### Author: ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)
#### Post date: [21. September 2018 um 15:47 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/7 "2018-09-21T15:47:44Z")

</div>

Hi Donny,

just saw your response. Thanks for the Info, but I already figured that out with the help of Postman. 😉

Danny

---

<div class="post-metadata">

### Author: ![sofmorona](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@sofmorona](https://forum.shopware.com/u/sofmorona)
#### Post date: [19. August 2024 um 21:02 UTC](https://forum.shopware.com/t/how-to-implement-a-webhook-endpoint-in-shopware/46504/8 "2024-08-19T21:02:29Z")

</div>

Hello!

I found it a very interesting thread. I am facing the same issue and I’ve followed your steps however once I’ve created the controller and access to [https://yourdomain.com/webhooks/index](https://yourdomain.com/webhooks/index) it makes a 301 and redirects me to the home page

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/e/d/ed6e45bdd0135576f3c3376b0eba7ecd54492326.png)

I’ve tried several things but always have the same 301, maybe is something in the configuration? I’ve tried also with the basic auth enabled but the result is the same…

Any help would be really appreciated.

Regards
