SW 6.6 admin Ajax request to custom controller does not work anymore

Hi to all!

I have a plugin where in an admin template I create an Ajax call to custom controller to get some data.
After the upgrade to v6.6 the call returns 404 - no route found. Is still possible to do this and if yes where I can find example how to do it? All links I found are for the Storefront.

Regards!

Looks like I made it, just replace in-comment route with the new syntax:

#[Route(path: ‚the_path‘, name: ‚the_api_name‘, defaults: [‚auth_required‘ => false, ‚XmlHttpRequest‘ => true], methods: [‚POST‘, ‚GET‘])]

I have teh same issue.
Can u show me your Controller please ?

this is my Controller

use Shopware\Core\Framework\Context;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpFoundation\JsonResponse;

#[Route(defaults: ['_routeScope' => ['api']])]
class TestController extends AbstractController
{
    private $services;

    public function __construct(iterable $services)
    {
        $this->services = $services;
    }

    #[Route(path: '/api/test/test-productioncheck', name: 'api.action.test.test-productioncheck', defaults: ['auth_required' => false, 'XmlHttpRequest' => true], methods: ["GET"])]
    public function index(Request $request, Context $context)
    {
        $result = [];

        foreach ($this->services as $checkService) {
            $result = array_merge($result, $checkService->getCheckResult());
        }

        return new JsonResponse([
            'data' => $result,
        ]);
    }
}

I want to display the data in the admin but I get a 404 error and the data are not displayed @miro

Your code looks ok, mine looks like this:

<?php declare(strict_types=1);

namespace Swag\directory_name\Administration\Controller;

// lot of use classes next

#[Route(defaults: ['_routeScope' => ['api']])]
/**
 * @author
 */
class OrderController extends AbstractController
{
   // some variables
   // then the constructor with lot of parameters in it
   // and one of my public methods looking like this:
   #[Route(path: '/api/company_name/check_order', name: 'api.action.company_name.check_order', defaults: ['auth_required' => false, 'XmlHttpRequest' => true], methods: ['POST', 'GET'])]
   /**
    * description here, then legacy route
    * @Route("/api/company_name/check_order", name="api.action.company_name.check_order", defaults={"auth_required"=false, "XmlHttpRequest"=true}, methods={"GET", "POST"})
     * 
     * @param Request $request
     * @param Context $context
     * 
     * @return JsonResponse
     */
   public function checkForOrder(Request $request, Context $context)
   {
      ...
      // and return JsonResponse at the end.
   }
}

That is all. Tested on version 6.6.1.0. I hope this can help you!

Regards!

PS - may be the only difference is you are using „-“ in the route, I use „_“. I am not sure your is wrong, but you can try to replace it.