Extracting data by means of an API

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Extracting data by means of an API

Post by RonP » 2021-10-25 18:12

Hi,
I'm looking for a way to extract data from a table by means of an API.
I would like to just access the zip codes, "indicator codes" (like "Member/Non Member") from the "Members Table".
With that data I would Plot a map.

What I do now is extracting this fields as .csv and then go to a plot application.
So if I could skip the extracting step ..... that would be great.
Is this possible or does this already exists?

Ron

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Extracting data by means of an API

Post by pbottcher » 2021-10-25 20:33

Hi Ron,

actually you can write a small php script that extracts your data and either save it as a csv file, or just echo it out.

Otherwise the is the API https://github.com/rafinhacarneiro/appgini-api that you may try.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: Extracting data by means of an API

Post by Alisson » 2021-10-26 16:25

If your plot application can import json data instead of csv, this code can help you.

Create a file called export.php inside your hooks folder

Code: Select all

<?php
    include("../lib.php");

    $query = sql("SELECT * FROM members", $eo);
    
    $json_array = array();  
    while($row = mysqli_fetch_assoc($query))  
    {  
        $data[] = $row;
    }  
    echo(json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));

?> 
By accessing the export.php it will generate the data you need in json format

Otherwise you can try this code that will output a csv data:

Code: Select all

<?php
    include("../lib.php");

    $query = sql("SELECT * FROM members", $eo);
    
    $json_array = array();  
    while($row = mysqli_fetch_assoc($query))  
    {  
        $data[] = $row;
    }  
    
     $jsondata = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);

    $jsonans = json_decode($jsondata, true);
    $file_pointer = fopen('php://output', 'w');
    foreach($jsonans as $i){
        fputcsv($file_pointer, $i);
    }
    fclose($file_pointer);

?> 
PS. Change the query to reflect your need.

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Extracting data by means of an API

Post by RonP » 2021-10-26 17:08

Hi PBöttcher and Alisson,
Thans you both to pointing to some solutions.
I’ll have werk to do :D
Ron

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Extracting data by means of an API

Post by RonP » 2021-12-29 10:39

Two months later ;)
Well, I've found someone within my volunteers club, he made a nice, secured, interactive plot for me.
Thank you for pointing to the solution.
A screen crab from the result :)

Ron
Attachments
Heiloo-Energie_map.JPG
Heiloo-Energie_map.JPG (106.54 KiB) Viewed 2000 times

Post Reply