Module Web Services API REST (developer): Difference between revisions

Jump to navigation Jump to search
m
Line 66: Line 66:




<source lang="php">function CallAPI($method, $apikey, $url, $data = false)
<source lang="php">
// Example of function to call a REST API
function callAPI($method, $apikey, $url, $data = false)
{
{
     $curl = curl_init();
     $curl = curl_init();
Line 96: Line 98:


     // Optional Authentication:
     // Optional Authentication:
//    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    //    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//    curl_setopt($curl, CURLOPT_USERPWD, "username:password");
    //    curl_setopt($curl, CURLOPT_USERPWD, "username:password");


     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader);


     $result = curl_exec($curl);
     $result = curl_exec($curl);

Navigation menu