Title: REST API error
Last modified: July 1, 2021

---

# REST API error

 *  Resolved [thenine](https://wordpress.org/support/users/thenine/)
 * (@thenine)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/rest-api-error-25/)
 * Hi,
 * I have a PHP script which calls the REST API through **get_file_content ()**,
 * This is the script
 *     ```
       $context = stream_context_create(
               array(
                   "http" => array(
                       "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
                   )
               )
           );
       $uri="http://mysite.com/wp-json/tribe/events/v1/events?page=1&per_page=50&start_date=2000-01-01" ;
   
       $json = file_get_contents($uri,false, $context);
   
       $posts= json_decode($json);
       ```
   
 * I call the script from the following url
 * [http://mysite.com/myscript.php](http://mysite.com/myscript.php)
 * Show me a error
 * Warning: file_get_contents([http://mysite.com/wp-json/tribe/events/v1/events?page=1&per_page=50&start_date=2000-01-01](http://mysite.com/wp-json/tribe/events/v1/events?page=1&per_page=50&start_date=2000-01-01)):
   failed to open stream: HTTP request failed! in myscript.php on line 12
 * But if I put url in a browser
 * [http://mysite.com/wp-json/tribe/events/v1/events?page=1&per_page=50&start_date=2000-01-01](http://mysite.com/wp-json/tribe/events/v1/events?page=1&per_page=50&start_date=2000-01-01)
 * Browser shows me results.
 * Why the script gives me an error ?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Deblyn Prado](https://wordpress.org/support/users/deblynprado/)
 * (@deblynprado)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/rest-api-error-25/#post-14681600)
 * Hi there [@thenine](https://wordpress.org/support/users/thenine/)!
 * I can’t see anything wrong in your code, I’ve just tried this using the following
   URL
 * `https://poised-xenomorph.w5.sandbox.moderntribe.qa/wp-json/tribe/events/v1/events?
   page=1&per_page=50&start_date=2000-01-01`
 * that’s a valid testing machine using The Events Calendar.
 * I can see the json generated.
 * You can try to print content of $json to see what’s returned from your API.
 *  [Marho](https://wordpress.org/support/users/matumu/)
 * (@matumu)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/rest-api-error-25/#post-14801648)
 * Hi there!
 * This thread has been inactive for a while so we’re going to go ahead and mark
   it Resolved.
 * Please feel free to open a new thread if any other questions come up and we’d
   be happy to help.
 * Best regards,
 * Marho

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘REST API error’ is closed to new replies.

 * ![](https://ps.w.org/the-events-calendar/assets/icon-256x256.gif?rev=2516440)
 * [The Events Calendar](https://wordpress.org/plugins/the-events-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/the-events-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/the-events-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/the-events-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/the-events-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/the-events-calendar/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [Marho](https://wordpress.org/support/users/matumu/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/rest-api-error-25/#post-14801648)
 * Status: resolved