Skip to content

Envato Marketplace API with CodeIgniter

2009 April 23
by Tom Schlick

Overview

So I created this library mostly out of boredom. It includes functions to interact with all of the options & functionality that the current version (“EDGE”) provides. It was designed to be a CodeIgniter library but it can easily be ported over to php in just a few steps. It allows you to output the data in json, array, or raw (the format that the request was [json, xml]). So lets get to it!

Download

[download id="1"]

Documentation

Configuration

There are several options you can set in the configuration that will make the library behave differently.

  • username – obviously your username for the envato marketplaces
  • api_key – your api key for the marketplaces ( you should never set this in view of the public, its sort of like a password ).
  • api_format – the format you want the library to request, this can be altered with the next option (output format) – options incude : json, array, xml (default is json)
  • output_format – the format you want the library to return to you. options: array (default), json, raw (unaltered/formatted data straight from the feed) note: to get xml format back you need to set this to raw and set api_format to xml

This is how you can set the config information with a simple function and array.
[code language='php']
$this->envato_api->config(array('api_format' => 'json', 'output_format' => 'array', 'username' => 'joesmith', 'api_key' => 'MYSUPERSECRETKEY'));
[/code]

Place the configuration code above the functions listed below.

Public Functions

These are functions that do not require a username and api key to access. They are mostly things such as the latest files on the marketplaces, the most popular threads, etc.

Blog Posts

A list of blog posts for a particular site. Requires a site parameter.

[code language='php']
$data = $this->envato_api->public_blog_posts('sitename');
$this->evanto_api->clear();
[/code]

Active Threads

Threads with the most recent messages activity. Requires a site parameter.

[code language='php']
$data = $this->envato_api->public_threads_active('sitename');
$this->evanto_api->clear();
[/code]

Number of Files in Categories

Shows the number of files in the major categories of a particular site. Requires a site paramater.

[code language='php']
$data = $this->envato_api->public_files_number('sitename');
$this->evanto_api->clear();
[/code]

Category New Files

New files, recently uploaded to a particular site. Requires site and category paramaters.

[code language='php']
$data = $this->envato_api->public_files_new('sitename', 'categoryname');
$this->evanto_api->clear();
[/code]

Popular Files

Returns the popular files for a particular site. Requires a site paramater.

[code language='php']
$data = $this->envato_api->public_files_popular('sitename');
$this->evanto_api->clear();
[/code]

New User Files

Shows the newest 10 files a user has uploaded to a particualr site. Requires username and site paramaters.

[code language='php']
$data = $this->envato_api->public_files_user_new('username', 'sitename');
$this->evanto_api->clear();
[/code]

Random New Files

Shows a random list of newly uploaded files from a particular site (i.e. like the homepage). Requires a site paramater.

[code language='php']
$data = $this->envato_api->public_files_new_random('sitename');
$this->evanto_api->clear();
[/code]

API Releases

Returns Release and Set information for the API (used to generate the documentation).

[code language='php']
$data = $this->envato_api->public_releases();
$this->evanto_api->clear();
[/code]

Private User Functions

These are functions that DO require a username and API key to access. They include things such as account information, billing statements, etc. Make sure to set your username & api key inside the script or with the config function above.

User Vitals

Return a users username and balance.

[code language='php']
$data = $this->envato_api->user_vitals();
$this->evanto_api->clear();
[/code]

User Account

Returns the first name, surname, total earnings, total deposits, balance (deposits + earnings), country and current commission rate for sales.

[code language='php']
$data = $this->envato_api->user_account();
$this->evanto_api->clear();
[/code]

User Earnings & Monthly Sales

Returns the monthly sales data, as displayed on the user’s earnings page.

[code language='php']
$data = $this->envato_api->user_earnings();
$this->evanto_api->clear();
[/code]

User Statement

Returns the last 100 events as seen on the user’s statement page.

[code language='php']
$data = $this->envato_api->user_statement();
$this->evanto_api->clear();
[/code]

User Recent Sales

Shows the 50 recent sales of the user’s items.

[code language='php']
$data = $this->envato_api->user_recent_sales();
$this->evanto_api->clear();
[/code]

User Multiple

This function will return multiple sets of data at once. if you dont supply anything in the parameters it will return all of the results by default. The options inside the array below are the only options you have. You can use as many or as little as you need.

[code language='php']
$data = $this->envato_api->user_multiple(array('account', 'vitals', 'earnings-adn-sales-by-month', 'statement', 'recent-sales'));
$this->evanto_api->clear();
[/code]

Done!

We are all done! If you have any questions, suggestions, bugs or just wanna say thanks then reply in the comments.

One Response leave one →
  1. April 23, 2009

    Nice! I didn’t know about the Envato marketplace at all … thanks for this! :-)

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS