PHP API User for module search

Hi everyone,
Is there a way to specify a different user when calling the php api? For example, I’d like to query the api for a list of modules, but when no user is logged in I get a PermissionDeniedException error. My thought was I could use the API credentials of a different user but I’m unable to get that work. Thanks for any help!

You can authenticate your requests using the key_identity and key_credential parameters. For example:

See our docs for more information:

Thanks for the feedback! I saw that for the rest API but I didn’t see that anywhere for the PHP API. Do you know if there’s a difference?

Where and how are you attempting to access the PHP API? Using the API manager within the application should circumvent authentication.

In a theme I’m working on, in one of the view files. I was trying to search the API to see if a module was activated and change something in the view depending on the result.

Ah, I see. It’s tricky. There’s no easy way to get a list of modules on the public site for a non-authenticated user. Views just don’t have access to the ways you could make this work.

Outside the view (say, in a view event or a Controller) you have several options. I recommend that you use the Omeka\ModuleManager service for direct access to the modules:

$modules = $serviceLocator->get('Omeka\ModuleManager')->getModules()

If you must use the API, you could masquerade as a user or modify the access control, but those options are far more complicated and come with some risk.

I understand. Thanks for your help with this!

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