# Trying to create an endpoint to receive API requests but is not working

**URL:** <https://forum.mautic.org/t/trying-to-create-an-endpoint-to-receive-api-requests-but-is-not-working/32700>\
**Category:** Development\
**Created:** [July 10, 2024, 12:58am UTC](https://forum.mautic.org/t/trying-to-create-an-endpoint-to-receive-api-requests-but-is-not-working/32700 "2024-07-10T00:58:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcarabelli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/rcarabelli/32/6807_2.png) [@rcarabelli](https://forum.mautic.org/u/rcarabelli)\
**Post date:** [July 10, 2024, 12:58am UTC](https://forum.mautic.org/t/trying-to-create-an-endpoint-to-receive-api-requests-but-is-not-working/32700/1 "2024-07-10T00:58:26Z")

</div>

**Your software**  
My Mautic version is: 5.1  
My PHP version is: 8.2  
My Database type and version is: MySQL

**Your problem**  
My problem is: I am trying to create an URI for my endpoint to send data to a plugin I already have but it seems something is wrong because is never really built.  
I just want, for now, to send a “hello” request to get a simple answer back but get this error:

[panales@cat ~]$ curl -X POST [https://marketautomation.lapañalera.com/api/zender/receive-hello](https://marketautomation.xn--lapaalera-o6a.com/api/zender/receive-hello) \

> -H “Content-Type: application/json”   
> -H “Authorization: Bearer ZjVjMDJlOTJlNzlmNGQ2MDgxYWVmNTY3YTgxYTFhOGU4ODQ1YzZlYzcwNTZkNjM5OWI3NmNiMzdjMzdjZZZZZZ”   
> -d ‘{“message”: “hola”}’  
> {“errors”:[{“message”:“Requested URL not found: /api/zender/receive-hello”,“code”:404,“type”:null}]}[panales@cat ~]$

And

[panales@cat marketautomation]$ php bin/console debug:router | grep receive-hello  
mautic\_zender\_receive\_hello GET https ANY /api/zender/receive-hello  
[panales@cat marketautomation]$

But the “receive-hello” part appears with red font.

In any case, the URL is not working, have added this to the config file of the plugin:

> ```
> 'routes' => [
> 'api' => [
> 'mautic_zender_receive_hello' => [
> 'path' => '/zender/receive-hello',
> 'controller' => 'MauticPlugin\MauticZenderBundle\Controller\ApiController::receiveHello',
> 'methods' => ['POST'],
> 'defaults' => [],
> ],
> ],
> ],
> 
> ```

and /home/panales/public\_html/marketautomation/plugins/MauticZenderBundle/Controller/ApiController.php

> \<?php namespace MauticPlugin\MauticZenderBundle\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ApiController extends AbstractController { public function receiveHello(Request $request) { if ($request-\>getContentType() !== 'json') { throw new BadRequestHttpException('Invalid content type'); } $data = json\_decode($request-\>getContent(), true); if (isset($data['message']) && $data['message'] === 'hola') { return new JsonResponse(['response' =\> 'recibido']); } return new JsonResponse(['error' =\> 'Invalid message'], 400); } }

And  
/home/panales/public\_html/marketautomation/plugins/MauticZenderBundle/Config/services.yaml

> services:  
> MauticPlugin\MauticZenderBundle\Controller\ApiController:  
> public: true  
> tags: [‘controller.service\_arguments’]

Mautic is not crashing at least and the rest of the plugin works as intended, but can’t get the API POST requests because the endpoint looks like it doesn’t exist.

This is the structure of the plugin

[panales@cat MauticZenderBundle]$ tree  
.  
├── Assets  
│ └── img  
│ ├── 7cats-isotipo-red-200x200.png  
│ └── whatsapp.png  
├── Config  
│ ├── config.php  
│ └── services.yaml  
├── Controller  
│ └── ApiController.php  
├── EventListener  
│ └── PluginActivatedEventListener.php  
├── Integration  
│ └── ZenderIntegration.php  
├── LICENSE  
├── MauticZenderBundle.php  
├── Migrations  
│ └── Schema  
│ └── Version0001.php  
├── README.md  
├── Translations  
│ └── en\_US  
│ └── messages.ini  
└── Transport  
└── ZenderTransport.php

11 directories, 13 files

These errors are showing in the log:

Steps I have tried to fix the problem: Read the documentation but find no specific reference to create an endpoint in a Plugin

---

<div class="post-metadata">

**Author:** ![rcarabelli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/rcarabelli/32/6807_2.png) [@rcarabelli](https://forum.mautic.org/u/rcarabelli)\
**Post date:** [July 10, 2024, 3:29am UTC](https://forum.mautic.org/t/trying-to-create-an-endpoint-to-receive-api-requests-but-is-not-working/32700/2 "2024-07-10T03:29:19Z")

</div>

Found my issue (that had since october)

I was writing the “methods” with “s” at the end and is “method”, singular

> ```
> 'routes' => [
> 'api' => [
> 'mautic_zender_receive_hello' => [
> 'path' => '/zender/receive-hello',
> 'controller' => 'MauticPlugin\MauticZenderBundle\Controller\ApiController::receiveHello',
> 'method' => ['POST'], // Lista de todos los métodos HTTP
> 'defaults' => [],
> ],
> ],
> ],
> 
> ```

This is the correct usage  
With the “s” at the end it only accepted the “GET” method

Found very useful this command: php bin/console debug:router \> routes.txt  
And the solution came from this example: [mautic-contact-source/Config/config.php at b8f128a26e8c64fc05bbaf86f7786f7a10f0e1ef · TheDMSGroup/mautic-contact-source · GitHub](https://github.com/TheDMSGroup/mautic-contact-source/blob/b8f128a26e8c64fc05bbaf86f7786f7a10f0e1ef/Config/config.php)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [July 11, 2024, 3:30pm UTC](https://forum.mautic.org/t/trying-to-create-an-endpoint-to-receive-api-requests-but-is-not-working/32700/3 "2024-07-11T15:30:04Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
