$item_id = 'xxxxxxxxx';
$purchase_code = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json; charset=utf-8';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.envato.com/v3/market/buyer/download?item_id=".$item_id."&purchase_code=".$purchase_code);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
Yeah, looks like you forgot to authenticate your API request with a personal token. You need to add the Authorization
and User-Agent
headers per the post linked by @mgscoder:
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json; charset=utf-8';
$header[] = 'Authorization: Bearer PERSONAL_TOKEN_HERE';
$header[] = 'User-Agent: Purchase code verification on mywebsite.com';
Here is a fully working code sample for verifying purchase codes, if you want to reference it:
Thank you @baileyherbert & @mgscoder
Your suggestion helps me lot to use API Programmaticaly.
Now, i am confused to use the API for my application.
I wanted to check the purchase code for specific Item.
- https://build.envato.com/api/#market_0_Buyer_Download
-
https://build.envato.com/api/#market_0_Buyer_Purchase
Which Application suits for my need.
Please Suggest me
Thank you
Neither of those check purchase codes. What you want is the one called “Look up sale by code” (https://build.envato.com/api/#market_0_Author_Sale).
First, make sure to generate a personal token. This is an API key that will allow you to connect to the Envato API. You cannot connect without it.
Then check this post, it has everything you need in code: How to verify a purchase code using the Envato API