modifiedcontent Posted September 27, 2021 Share Posted September 27, 2021 I am trying to connect with an external API, from marketing automation application Mautic on the same server, from a template in Processwire, with something like this: require '/serverpath/vendor/autoload.php'; use Mautic\Auth\ApiAuth; use Mautic\MauticApi; $initAuth = new ApiAuth(); This works in an empty test page outside of Processwire. Trying to use it from a template within Processwire I get this error: Quote Fatal Error: Uncaught Error: Class 'ApiAuth' not found in site/templates/session.php:43 #0 wire/core/TemplateFile.php (318): require() #1 wire/core/Wire.php (394): TemplateFile->___render() #2 wire/core/WireHooks.php (823): Wire->_callMethod('___render', Array) #3 wire/core/Wire.php (465): WireHooks->runHooks(Object(TemplateFile), 'render', Array) #4 wire/modules/PageRender.module (536): Wire->__call('render', Array) #5 wire/core/Wire.php (397): PageRender->___renderPage(Object(HookEvent)) #6 wire/core/WireHooks.php (823): Wire->_callMethod('___renderPage', Array) #7 /wire/c (line 43 of site/templates/session.php) How can I make sure the script looks for Mautic's ApiAuth in the correct place? Mautic's autoload.php is included in the page successfully; I have checked that. Link to comment Share on other sites More sharing options...
Rudy Posted September 27, 2021 Share Posted September 27, 2021 Try adding a backslash prefix in front of the class namespace use \Mautic\Auth\ApiAuth; use \Mautic\MauticApi; 1 Link to comment Share on other sites More sharing options...
modifiedcontent Posted September 27, 2021 Author Share Posted September 27, 2021 @Rudy, thanks for the idea. I tried this, but it didn't make any difference, even after clearing caches etc. Edit: I figured it out. In the script I "called" the API with this: $initAuth = new ApiAuth(); When I should have used: $initAuth = new Mautic\Auth\ApiAuth(); To "declare" (?) the namespace. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now