Forum Discussion

ahmirof's avatar
ahmirof
Copper Contributor
Sep 18, 2022

How import data from Json API

Hi,
I have a website and people can import data from my website by an API key to their own website.

But now I am trying to import the data which is a service list to an Excel sheet.
This is my website API document URL : https://neofollower.com/panel/api/docs

 

I want to import the "Services List"

it has two parameters :
key = Your API key
action =  services

and the API URL: https://neofollower.com/panel/api/docs

the API key is unique for every user

My excel is Professional Plus 2021

I tried with Data-> New query -> From other resources -> From web

then :

URL parts: https://neofollower.com/panel/api/docs
HTTP request header :
key = my API key
action=  services

but i don't get any results (it says the API key is disabled or didn't connect, but API is work perfectly in other websites)
what should I do?

2 Replies

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor

    https://neofollower.com/panel/api/docs

    From this document,this is a POST submit instead of GET.

    example PHP

    <?php
    class Api {
        // API URL
        public $api_url = 'http://yourwebsite.com/api/v1'; 
    
        // Your API key
        public $api_key = ''; 
    
        /**
         *
         * Add Order
         *
         */
        public function add_order($data) { 
            $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
            $result = $this->connect($post);
            return json_decode($result);
        }
    
        /**
         *
         * Order status
         *
         */
        public function status($order_id) { 
            $result = $this->connect(array(
                'key'    => $this->api_key,
                'action' => 'status',
                'order'  => $order_id
            ));
            return json_decode($result);
        }
    
        /**
         *
         * Order multi status
         *
         */
    
        public function multi_status($order_ids) { 
            $result = $this->connect(array(
                'key'        => $this->api_key,
                'action'     => 'status',
                'orders'     => implode(",", (array)$order_ids)
            ));
            return json_decode($result);
        }
    
    
        /**
         *
         * All services
         *
         */
        public function services() { 
            $result = $this->connect(array(
                'key'     => $this->api_key,
                'action'  => 'services',
            ));
            return json_decode($result);
        }
    
        /**
         *
         * Balance
         *
         */
        public function balance() { 
            $result = $this->connect(array(
                'key'     => $this->api_key,
                'action'  => 'balance',
            ));
            return json_decode($result);
        }
    
        /**
         *
         * Connect to panel
         *
         */
        private function connect($post) {
            $_post = Array();
    
            if (is_array($post)) {
              foreach ($post as $name => $value) {
                $_post[] = $name.'='.urlencode($value);
              }
            }
    
            if (is_array($post)) {
              $url_complete = join('&', $_post);
            }
            $url = $this->api_url."?".$url_complete;
    
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_USERAGENT, 'API (compatible; MSIE 5.01; Windows NT 5.0)');
            $result = curl_exec($ch);
            if (curl_errno($ch) != 0 && empty($result)) {
              $result = false;
            }
            curl_close($ch);
            return $result;
        }
    
    }
    
    // Examples
    $api = new Api();
    
    # return all services
    $services = $api->services(); 
    
    # return user balance
    $balance = $api->balance(); 
    
    // add order
    $order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100)); # Default
    
    $order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'comments' => "good pic\ngreat photo\n:)\n;)")); # Custom Comments
    
    $order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'runs' => 10, 'interval' => 60)); # Drip-feed
    
    # return status, charge, remains, start count, order_id
    $status = $api->status(23); 
    
    # return orders status, charge, remains, start count, order_id
    $statuses = $api->multi_status([12, 2, 13]); 

     

  • an_an's avatar
    an_an
    Copper Contributor

    When using Excel’s Get & Transform (Power Query) to pull JSON from an API, you usually need to send parameters either in the URL or in the body of a POST request, not as request headers. That’s likely why you’re not seeing results.

    Try this approach:

    Go to Data → Get Data → From Other Sources → From Web.
    In the dialog, switch from “Basic” to Advanced.
    Put the API endpoint URL in the first box (something like https://neofollower.com/panel/api/v2 if that’s the actual API base).
    Add the parameters (key=YOUR_API_KEY and action=services) in the query string or request body depending on what the API expects.
    Power Query should then return the JSON, which you can expand into rows and columns.

    If it still fails, double-check the API docs: some services expect a POST request with form data, which Excel can’t always handle natively. In that case, a small VBA macro or PowerShell/Python script may be needed to fetch the JSON and load it into Excel.

Resources