Envato API PHP Code Samples

Here’s some code samples for working with the new Envato API

These will help people migrate as the old API is getting shut down.

Simple verify-purchase through the new API

WordPress oAuth PHP Class Example

This is a simple PHP class for interacting with the Envato API within a WordPress plugin. It uses some of the WordPress functions like wp_remote_get()

Simple usage example:

$envato_api = envato_api_basic::getInstance();
$code = !empty($_GET['code']) ? $_GET['code'] : false;
if($code && $token = $envato_api->get_authentication($code) && $envato_api_result = $envato_api->api('v1/market/private/user/username.json')){
   // user is logged in with oAuth
      echo "Welcome ".htmlspecialchars($envato_api_result['username']);
      echo "API Error, unable to get username.";
   $login_url = $envato_api->get_authorization_url();
   echo '<a href="'.esc_url($login_url).'" target="_blank"> Login with Envato </a>';



Drupal oAuth PHP Class Example

This was created by Envato user sowailem.  It uses some special drupal code so probably best to only be used inside a drupal environment. However it’s a great example of a class and can be pulled apart to adapt to other platforms.


Leave a Reply

Your email address will not be published.