How to call REST API using CURL in php?
<p>I have problem when I am trying to call API using curl. My php code looks like this:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;body&gt;
&lt;span style="z-index:50;font-size:0.9em;"&gt;
&lt;img src="https://theysaidso.com/branding/theysaidso.png" height="20"  width="20" alt="theysaidso.com"/&gt;
&lt;a href="https://theysaidso.com" title="Powered by quotes from   theysaidso.com" style="color: #9fcc25; margin-left: 4px; vertical-align:  middle;"&gt;
theysaidso.com&lt;/a&gt;&lt;/span&gt;
&lt;?php
       $service_url = 'http://quotes.rest/qod.json';
       $curl = curl_init($service_url);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POST, false);
       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
       $curl_response = curl_exec($curl);
       curl_close($curl);
       $json_objekat=json_decode($curl_response);
       echo $json_objekat-&gt;contents-&gt;quotes-&gt;quote.'&lt;br&gt;';
       echo $json_objekat-&gt;contents-&gt;quotes-&gt;author.'&lt;br&gt;';    
?&gt;
&lt;/body&gt;
&lt;/head&gt;
</code></pre>

<p></p>

<p>This code is saved as php file in my root directory on WAMP server. I use WAMP server. And it is written on this website  <a href="http://quotes.rest/qod.json" rel="nofollow">http://quotes.rest/qod.json</a> that you must insert this html too. When I open this php page on WAMP it shows alert:</p>

<blockquote>
  <p>Notice: Undefined property: stdClass::$contents in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 18</p>
  
  <p>Notice: Trying to get property of non-object in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 18</p>
  
  <p>Notice: Trying to get property of non-object in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 18</p>
  
  <p>Notice: Undefined property: stdClass::$contents in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 19</p>
  
  <p>Notice: Trying to get property of non-object in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 19</p>
  
  <p>Notice: Trying to get property of non-object in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 19</p>
</blockquote>

<p>JSON on this link <a href="http://quotes.rest/qod.json" rel="nofollow">http://quotes.rest/qod.json</a> looks like this:</p>

<pre><code>{
    "success": {
        "total": 1
    },
    "contents": {
        "quotes": [
            {
                "quote": "A loser doesn't know what he'll do if he loses, but talks about what he'll do if he wins, and a winner doesn't talk about what he'll do if he wins, but knows what he'll do if he loses.",
                "length": "184",
                "author": null,
                "tags": [
                    "failure",
                    "inspire",
                    "knowledge",
                    "winning"
                ],
                "category": "inspire",
                "date": "2016-05-11",
                "title": "Inspiring Quote of the day",
                "background":       "https://theysaidso.com/img/bgs/man_on_the_mountain.jpg",
                "id": "KhjRMynny89MKxcGkEKF_QeF"
             }
        ]
    }
}
</code></pre>

<p>When I change last two lines in php to this:</p>

<pre><code>   echo $json_objekat['contents']['quotes']['quote'].'&lt;br&gt;';
   echo $json_objekat['contents']['quotes']['author'].'&lt;br&gt;';   
</code></pre>

<p>it alerts:</p>

<blockquote>
  <p>Fatal error: Cannot use object of type stdClass as array in
  C:\wamp\www\IzdavackaKuca\javniServis.php on line 18</p>
</blockquote>

<p>I realy don`t know how to call this server, when I code:</p>

<pre><code>&lt;?php
   $defaults = array(
        CURLOPT_URL             =&gt; 'http://quotes.rest/qod.json',
        CURLOPT_POST            =&gt; false,
        CURLOPT_HEADER          =&gt; false,
        CURLOPT_SSL_VERIFYPEER  =&gt; false,
        CURLOPT_RETURNTRANSFER  =&gt; true,
        CURLOPT_SSL_VERIFYHOST  =&gt; false,
    );
    $curl               = curl_init();
    curl_setopt_array($curl, $defaults);
    $curl_response      = curl_exec($curl);
    $json_objekat       = json_decode($curl_response);

    // DUMP THE CURL-ERROR INFORMATION:
    var_dump(curl_error($curl));
    curl_close($curl);
?&gt; 
</code></pre>

<p>it alerts:</p>

<blockquote>
  <p>string '' (length=0)</p>
</blockquote>

<p>Please help!</p>