3

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>
        </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()
{
 $this->_curl->get('https://online.jil.com/api/index.aspx?action=GetAllDIDs');
    $response = $this->_curl->getBody();
    echo $response;
}
8

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);

    print_r($output);
}

Note: API Key is generated for Specific Domain

I Hope This Helps You

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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