Go to Tracker Support

Tracker Support

Search for any help questions or topics.

Example PHP Function

For calling the Tracker API
Avatar
Will Hemming
Updated 5 years ago
ο»ΏThe function below allows you to pass your api_key, the URL you want to call, a $postdata array, and the type of request (POST/GET) to a function, and get the JSON response back.


function tracker3_api($api_key, $url, $postdata='', $requesttype='POST') {

    $http_content = array('access_token'=>$api_key);

    if($postdata) {
        foreach ($postdata as $key => $value) {

                $http_content[$key] = $value;
        }
    }

    if($requesttype=="GET") {
    
            $query_string = http_build_query($http_content);

            $url .= '?'.$query_string;

            $response = file_get_contents($url);

    
    } else {

            $stream_options = array(
                'http' => array(
                    'method'  => $requesttype,
                    'header'  => 'Content-type: application/x-www-form-urlencoded'."\r\n",
                    'content' =>  http_build_query($http_content)));

            $context  = stream_context_create($stream_options);

            $response = file_get_contents($url, null, $context);            
    
    }

    return $response;

}
😞 😐 πŸ˜ƒ