Api implementation in Admin Panel

Hello… i want to sell my android app on codecanyon. It`s an app with admin panel and i want to ask someone to help me with the Envato API Implementation in admin script for purchase verification.

Please help me. is this code good:

$code= trim($_GET['purchase-code']); // have we got a valid purchase code?
$url = "https://api.envato.com/v3/market/author/sale?code=".$code;
$curl = curl_init($url);
$personal_token = "personal token from envato";
$header = array();
$header[] = 'Authorization: Bearer '.$personal_token;
$header[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.0';
$header[] = 'timeout: 20';
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
$envatoRes = curl_exec($curl);
$envatoRes = json_decode($envatoRes);
$date = new DateTime($envatoRes->supported_until);
$boughtdate = new DateTime($envatoRes->sold_at);
$bresult = $boughtdate->format('Y-m-d H:i:s');
$sresult = $date->format('Y-m-d H:i:s');
	if (isset($envatoRes->item->name)) {   
			$data = " - Verification Success:  ({$envatoRes->item->name})  -  (Bought Date: {$bresult} )  - (Support Till: {$sresult})";
	} else {  
			$data= " - FAILED: Invalid Purchase Code";
echo $data;


thanks in advance!!

You can check this Tutorial Solution from @baileyherbert

1 Like

Hi @ibramelvis91,

Your code works fine, just make sure that your personal token has the “View the user’s items’ sales history” permission. Here’s the output that I received:

- Verification Success: (SEO Studio - Professional Tools for SEO) - (Bought Date: 2017-04-15 23:50:10 ) - (Support Till: 2018-04-16 06:50:10)

I do recommend checking my sample code in the link @mgscoder provided above – there are many ways your current code can generate unexpected errors, all of which I address in that code.

Also, you should definitely change your user agent to something that isn’t a browser so your requests don’t look suspicious. Even something like this will work fine:

$header[] = 'User-Agent: Purchase verification';


1 Like

Thank you baileyherbert for your answer !!!

1 Like