Envato Marketplaces API Introduction for PHP – The Public Set

stdClass Object
(
[number-of-files] => Array
(
[0] => stdClass Object
(
[category] => JavaScript
[number_of_files] => 1402
[url] => http://codecanyon.net/category/javascript
) [1] => stdClass Object
(
[category] => PHP Scripts
[number_of_files] => 2096
[url] => http://codecanyon.net/category/php-scripts
) [2] => stdClass Object
(
[category] => .NET
[number_of_files] => 132
[url] => http://codecanyon.net/category/net
) . . . etc . . .

echo ‘<pre>’;
print_r( number_of_files_codecanyon() );
echo ‘</pre>’;

There are two sides to the Envato Marketplaces API. The first is the public set (which I will cover in this article) and the other is the private set. The main difference between them is the fact that the private one requires a valid API key. Check out the other differences below;

  • Public:
    • Doesn’t require an API key.
    • Returns general/publically available data such as;
      1. The number of files currently available on a marketplace.
      2. The details of an item (such as price etc).
      3. Public user information (such as number of sales/followers, profile image URL, location etc.)
      4. Search data – this performs a search query on one of the sites and returns the first 50 items.
      5. Popular files on a marketplace.
      6. Featured files on a marketplace.
      7. New files on a marketplace.
  • Private:
    • Used to return secure information, such as your balance and earnings.
    • Can be used to;
      1. Return the last 100 items on your statement.
      2. Verify a purchase of your item (this requires your customer’s purchase key).
      3. Download a file you have purchased.

I have only listed a couple of the most useful above, but there are many more. Read the documentation to find out more.

The Code

Although I am not going to go through every possible data channel here, all of them are explained in the API Documentation.
Let’s dive in head first! The structure for all our code in this tutorial will be very similar; we will use PHP cURL to retrieve JSON data from the API, which we will then convert to a PHP object and use. Below is an example of the basic anatomy of our functions (this particular function will return all the CodeCanyon categories with the number of files in each);

function number_of_files_codecanyon() {
// Open cURL channel
$ch = curl_init(); // Set cURL options
curl_setopt($ch, CURLOPT_URL, “http://marketplace.envato.com/api/edge/number-of-files:codecanyon.json”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Decode returned JSON
$output = json_decode(curl_exec($ch), true); // Close Channel
curl_close($ch); // Return output
return $output;
}

Array
(
[item] => Array
(
[id] => 5850316
[item] => TCWP – Supercharged Twitter Card Management for WP
[url] => http://codecanyon.net/item/tcwp-supercharged-twitter-card-management-for-wp/5850316
[user] => InfinityCode
[thumbnail] => http://3.s3.envato.com/files/87961812/TCWPLogo.png
[sales] => 13
[rating] => 5.0
[rating_decimal] => 5.00
[cost] => 18.00
[uploaded_on] => Mon Oct 14 18:16:01 +1100 2013
[last_update] => Fri May 02 05:47:29 +1000 2014
[tags] => cards, customer, embed, integration, meta, outreach, photo, player, product, seo, social, social media, summary, twitter, twitter cards
[category] =&gt; wordpress/social-networking
[live_preview_url] => http://1.s3.envato.com/files/89907849/TCWPHeader.jpg
[live_preview_video_url] => https://fastdomain.com.au/wp-content/uploads/sites/8/2022/05/envato-marketplaces-api-introduction-for-php-the-public-set.mp4
) )

  • Retrieve Featured Item (and Free File of the Month); URL: http://marketplace.envato.com/api/edge/features:{ MARKETPLACE_NAME }.json The ‘MARKETPLACE_NAME’ parameter accepts a string. This corresponds to the lowercase name of the marketplace to be queried, eg. ‘codecanyon’, ‘activeden’ etc. This will return the following JSON data;
    Thankfully, Envato allows and encourages this form of interaction via its Marketplaces API. You can check out the official documentation here; http://extras.envato.com/api/. In this article I will cover the public side of this API, including how to use it and provide you with a useful snippet you can customise and drop right into your own projects. At the end I will also share my top 4 data channels in the API, showing you how to use them and what data they will return. Please note that a basic knowledge of using PHP objects will be required. Ready? Let’s begin then.

    That’s it for the basics! Now let’s have a look at some of the specific uses.

    Hello guys! I’m excited to be writing my debut article for WPKube and today I’m going to talk to you about Envato’s Marketplaces API. Envato is the largest and, in my opinion, possibly one of the most relevant online companies today when it comes to premium WordPress items. With Themeforest.net currently standing at over 4000 premium WordPress themes and Codecanyon.net with over 2500 WordPress plugins, interacting with the marketplaces has become even more important for advertisers in recent times.

    My Top 4 Most Useful Data Channels

    1. Retrieve Item data; URL: http://marketplace.envato.com/api/edge/item:{ ITEM_ID }.json The ‘ITEM_ID’ parameter accepts an integer. This corresponds to the unique ID given to a product by Envato. This will return the following JSON data;

      // Retrieve data from function
      $json_data = number_of_files_codecanyon(); // Count number of array items (-1 as the object is zero-based)
      $data_count = count($json_data[‘number-of-files’]) -1; // Output as list echo ‘<ul>’; // Echo code for every category
      for($i = 0; $i <= $data_count; $i++) { // Retrieve and print data echo ‘<li><a href=”‘.$json_data[‘number-of-files’][$i][‘url’].'”>’,$json_data[‘number-of-files’][$i][‘category’],'</a> – ‘,$json_data[‘number-of-files’][$i][‘number_of_files’],'</li>’;
      }
      echo ‘/<ul>’;

      This will return the following HTML;

      Posted by WordPress Guru