Getting an HTML response instead of JSON for thrown error during API call

Pimcore v6.4.2 I am getting an HTML response instead of JSON for the below error thrown during API call.

return new AccessDeniedHttpException(‘API request needs either a valid API key or a valid session.’, $previous);

Is their anyone who can help.

@rajesh17692 Can you share the screenshot of your code as this works fine for me to understand the issue?

@rahulshrivastava please find the below screenshot I am passing invalid token in header

Header option was added on v6.4.1 please use query parameter token.

Ohh, just saw you are using 6.4.2 it should work then

@dvesh3 I checked but it’s not working not able to find any solution.

@rajesh17692 how are you passing the apikey in header?

this works for me

Yes @dvesh3 I am passing the way and it’s not working, but in other pimcore project it’s working so I want to understand what I am missing I compared every configuration with that project but not found anything different.

I am passing same way

I checked and found that with Pimcore v6.4.2 version below file is missing can anyone suggest which file I can use instead

\Pimcore\Bundle\AdminBundle\Security\Guard\WebserviceAuthenticator

Checked file is available on path and has function

private function createAccessDeniedException(\Throwable $previous = null)
{
return new AccessDeniedHttpException(‘API request needs either a valid API key or a valid session.’, $previous);
}

Which itself returns HTML instead of JSON.

please check your logs…might be authentication failure https://github.com/pimcore/pimcore/blob/2662d44a8828ad8fc7c8d878020b115f8ba61d69/bundles/AdminBundle/Security/Guard/WebserviceAuthenticator.php#L165

checked everything but no solution available
working correctly with correct X-api-key

gives above error when passing incorrect key