question

jemsmark avatar image
jemsmark asked atul published

How to get JSON data using REST API in php?

I Hope someone help me, Is there any way get merchants,customer,employee, employee etc data using php REST API, please help how it work step by step. advance thank you. :)

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

James Tickett avatar image
James Tickett answered

The REST API can do that, and is easy to learn, but you will need to do the php coding part yourself. It looks like "jsonencode" and "jsondecode" are two libraries that come with PHP that you could use. You will also need to set the header with the API token.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

atul avatar image
atul answered

This is how you can get json data

     function curlPost($url,$post_data = NULL) {
       $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . 	$this->access_token));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $this->access_token
        )                                                                       
        );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        if($post_data != NULL){
            curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($post_data));
        }
        $data = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        return $data;
    }
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

atul avatar image
atul answered atul published
I m working on REST Api in PHP and I could get all the data from clover api but its taking long time to load the data. How can we reduce the time in order to get the data. Your suggestions would be appreciable.
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community