Skip to main content
5 of 5
added 118 characters in body
maidan
  • 463
  • 2
  • 7

API access without accept header

So this issue has already been noticed here:
https://github.com/joomla/joomla-cms/issues/39332

My component gets accessed via the API by a big company who is using the same access with hundreds of partners all over the world.

What they do is sending only this as header:

Cache-Control: no-cache
Content-Type: application/json

It works with all partners but Joomlas route function is missing the HTTP_ACCEPT in the header and so $mediaType is empty and throwing a:

"Could not match accept header"

What can be done to have a successful API access without the partner having to send a accept header?

Update 16.01.2024

I also tried accepting different headers, but seams i cannot handle an missing accept header. This in the route creation of my webservice plugin:

public function onBeforeApiRoute(&$router)
{
    $defaults    = [
        'component'  => 'com_mycomp',
        'format' => [
            'application/ld+json',
            'application/json',
        ],
    ];
    $getDefaults = array_merge(['public' => false], $defaults);

    // not working
    // $app = Factory::getApplication();
    // $app->setHeader('Accept', '*/*');

    $routes = [
        new Route(['GET'], 'v1/mycomp/time', 'mycomp.displayItem', [], array_merge(['endpoint' => 'time'], $getDefaults)),

It is described here:
https://github.com/joomla/joomla-cms/issues/39495

The getBest Function of the Negotiator requires a header:

if (!$header) {
   throw new InvalidArgument('The header string should not be empty.');
}
maidan
  • 463
  • 2
  • 7