I built a custom module. Its admin tables with CRUD functionality. I am putting a new button on the grid via the Ui_component listing XML file. When this button gets clicked I want to call a 3rd party API to load data into the current table.

This is the code for the button:

<item name="refresh" xsi:type="array">
            <item name="name" xsi:type="string">add</item>
            <item name="label" xsi:type="string" translate="true">refresh</item>
            <item name="class" xsi:type="string">primary</item>
            <item name="url" xsi:type="string">*/*/refreshAction</item>

The refraction controller is where I need help with the code to make the API call. For now, I just want to echo out the response, once I get the API call to return a successful response I will deal with actually saving the data to the table. The code I have now that's returning a 500 internal server error looks like this:

public function execute()
    $response = $this->_curl->getBody();
    echo $response;

2 Answers 2


I call Google Map API for get Latitude and Longitute of the specific location parameter

I used this code in controller

public function execute()
    $url ="https://maps.googleapis.com/maps/api/geocode/json?address=%27White+House,+Pennsylvania+Avenue+Northwest,+Washington,+DC,+United+States%27&sensor=true_or_false&key=AIzaSyA28OnwaqgoNtdbtCBAvfD6wUJnvzBrroE";

    $geocodeFromAddr = file_get_contents($url);

    $output = json_decode($geocodeFromAddr);


Note: API Key is generated for Specific Domain

I Hope This Helps You


Magento doesn't provide a centralize way to make api REST call to external services.
I worked with lot of customers and developers always use their own REST implementation, using multiple libraries like Guzzle, Curl, Zend...

That's why I recommand you to use this module to industialize your REST API call through Guzzle library: https://github.com/zepgram/module-rest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.