Element API calling Module that integrates with third-party plugin This is probably a bit niche but anyone especially au fait with the element api here?

On project X I have a custom module within which I am referencing a service from another plugin (bolden/google-maps-api). If I access the module directly (eg via a controller or variable belonging to my module) then all works fine.

However - if I try and access my module service from within an element api endpoint, then the service doesn't work (or rather returns null when trying to access the third-party plugin/service).

For example, in my endpoint I am calling the service ($location is a string): 

$data = MyModule::getInstance()-&gt;ServiceName-&gt;ServiceMethod( $location );

But this returns the following Response: Call to a member function placeFromText() on null (the stack trace highlights the corresponding line within my module/service), eg:

$googleMaps = GoogleMapsApi::getInstance();
$result = $googleMaps-&gt;googleMapsApiService-&gt;placeFromText( $place, 'geometry' );        


The same query, when accessed within my module (eg a controller or variable), works fine and returns a data object from the Google Maps API (as expected).

Bit confused - anyone have any thoughts on why this service isn't accessible from my module when accessed via the element API?

Any thoughts on this issue would be much appreciated!

Cole
You have to use full namespaces in Element API because anything within those functions is out of scope. So you need to use the full path to the Google class.

$googleMaps = new \Vendor\Module\GoogleMapsApi();


Putting a "use" directive at the top of the file will not work.

I had the exact same problem and that resolved my issues immediately.