23 posts
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 2
  • 8 Years of Membership
+2 more

Hello coders! I’m so exited about the introduction of the API that I needed to share my personal code that I use to test this new feature.

This example code will get the non-experienced coders started in testing and playing with the new API . It uses JSON instead of the more logical XML only because it’s more fun to play with when you want speed and not elegance (I might do this again in XML some time).

I got the example username and api-key from the introduction post (http://themeforest.net/forums/thread/a-brief-introduction-to-the-api/10945)

I used json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0)

Colored version of the code: http://lygon.net/themeforest.phps

<?php <br?>$api = “http://marketplace.envato.com/api/”; // Url of the actual API
$version = “edge”; // Edge is the development version, releses will be numbers
$username = “ryan”; // Your username
$apikey = “26k6otse2s586e4hcbzjy3quq830t3o4”; // Your api key
$sets = “vitals+recent-sales”; // sets you want to get. Format: set+otherset+etc

$url = ”$api$version/$username/$apikey/$sets.json”;
$rawdata = file_get_contents($url); // We get the contents, if you have remote locations disabled in your php.ini, you can use curl or something else here to get the actual HTTP data
$data = json_decode($rawdata, true); // Sets $data variable as the decoded json file in array

// Up to you (I’m assuming you know what to do with the array)
print_r($data); // This example just outputs the data, could be usefull for debugging

?> $version 

578 posts
  • 10 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 1
+6 more

That is brilliant!

May I suggest using http://pastie.caboo.se for code samples? That way we probably wont have any problem with our forums bonking up the code :)

But thanks!

Also, if anyone is doing a JS or AS example, remember you can just get the JSON response and go data = eval(response) and then access it like data['vitals']['balance'] !!!

105 posts
  • 8 Years of Membership
  • Affiliate Level 2
  • Author Level 3
  • Beta Tester
+4 more

Great :D