Envato marketplace API PHP wrapper
Envato Marketplace API class provides methods to view your items, search the marketplace, get personal, private data, view collections, etc. It also will automatically caches the results – so that you don’t hammer the API needlessly!
Usage
First, include the class in your project.
require 'Envato_marketplaces.php';
Next, create a new instance of the class:
$Envato = new Envato_marketplaces();
function object_to_array($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
Envato Marketplace API class Examples :
Getting Acount Information
require 'Envato_marketplaces.php';
$Envato = new Envato_marketplaces();
$Envato->set_api_key(' you api key ');
$account_info = $Envato->account_information(' username ');
$details = object_to_array($account_info);
print_r($details);
will return :
- image
- firstname
- surname
- total_earnings
- total_deposits
- balance
- country
- current_commission_rate
Account Balance
You can get the account balance within the account information Or by a stand-alone method.
require 'Envato_marketplaces.php';
$Envato = new Envato_marketplaces();
$Envato->set_api_key(' you api key ');
echo $Envato->balance(' username ');
will return the user’s balance e.g: 140$.
Most Popular Items Last Week
$pop = $Envato->most_popular('codecanyon');
$items = object_to_array($pop);
the array $items contains three arrays :
- Most Popular Items Last Week
- Most Popular Items Last Three Months
- Most Popular Authors Last Month
to get each array we should assign it when fetching :
// for the Most Popular Items Last Week
foreach ($items['items_last_week']
AS $item) {
}
the array keys :
- item
- sales
- user
- rating
Most Popular Items Last Three Months
// for the Most Popular Items Last Three Months
foreach ($items['items_last_three_months']
AS $item) {
}
the array keys :
- item
- sales
- user
- rating
Most Popular Authors Last Month
// for the Most Popular Authors Last Month
foreach ($items['authors_last_month']
AS $item) {
}
the array keys :
- image
- url
- item (which is the username here)
- sales
Search
$search = $Envato->search('slider');
and we can filter the search to a custom marketplace by adding a second parameter to the search function.
$search = $Envato->search('slider','codecanyon');
we can also make the search more accurate by adding a third parameter to the search function which is the category.
$search = $Envato->search('slider','codecanyon','plugins');
Getting User’s Items As Thumbnails
$Envato->display_thumbs('username');
// we can filter the result to a custom marketplace
$Envato->display_thumbs('username', 'marketplace');
// we can limit the result to a custom number
$Envato->display_thumbs('username', 'marketplace', 'limit');
Item Details
$item = $Envato->item_details('item_id');
$details = object_to_array($item);
will return array with keys :
- item : the item title
- url : the link to item page
- thumbnail : 80X80 px image
- user : the item owner username
- sales
- rating
- cost : the item price
- uploaded_on : first release date and time
- last_update
- tags
- category
- live_preview_url : 590X300 px image
Get Recent Sales Data
$Envato = new Envato_marketplaces();
$Envato->set_api_key(' your api key ');
$sales = $Envato->recent_sales(' your username ', 'limit');
$recent_sales = object_to_array($sales);
results an array with latest sales data such as :
- item
- amount
- rate
- sold_at
Get Earnings and Sales by Month
$Envato = new Envato_marketplaces();
$Envato->set_api_key(' your api key ');
$monthly_earnings = $Envato->earnings_by_month(' your username ');
$earnings = object_to_array($monthly_earnings);
results an array contains months, earnings and sales :
- month
- earnings
- sales
![5 Bestsellers Admin Templates [Themeforest Marketplace]](http://pluscss.com/wp-content/uploads/2014/05/351413883873041-150x150.jpg)






