To check purchase codes, you’ll need to create a “personal token.” This token works like a password but is only for API access and gives limited permissions to your account.
Go to Envato’s Token Creation Page. If you aren’t signed in, you’ll be asked to log in.
When creating your token, you need to select the following permissions:
After your token is created, copy and save it in a secure place. Envato will not show it again, so make sure to store it safely.
Your personal token is important and gives limited access to your account. It’s essential to keep it secure.
When working with the Envato API, there are a few important things to keep in mind. Carefully follow the steps below to avoid common mistakes, especially the warnings marked with caution signs.
Before sending a purchase code to the API, you should validate the input. Purchase codes follow the UUID v4 format, and you can use a regular expression to ensure the code is correct before making a request. This helps avoid unnecessary errors that can break your code.
Use this regular expression to validate purchase codes:
To send a purchase code validation request to the Envato API using Postman, follow these steps:
In the URL field, enter the following API endpoint (replace PURCHASE_CODE_HERE with the actual purchase code you want to verify):
https://api.envato.com/v3/market/author/sale?code=PURCHASE_CODE_HERE
For example, if your purchase code is 123e4567-e89b-12d3-a456-426614174002, the URL would look like this:
https://api.envato.com/v3/market/author/sale?code=123e4567-e89b-12d3-a456-426614174002
Key | Value |
---|---|
Authorization | Bearer YOUR_PERSONAL_TOKEN_HERE |
User-Agent | Purchase code verification (or any description of your application) |
For example, if your personal token is s6IscWrJL3NsBnqvUy6Q3XiImvcZlwkn, your headers would look like this:
Key | Value |
---|---|
Authorization | Bearer s6IscWrJL3NsBnqvUy6Q3XiImvcZlwkn |
User-Agent | Purchase code verification |
If the purchase code is valid and belongs to one of your buyers, Postman will return a JSON response like this:
<?php // Get the purchase code from the query string $code = isset($_GET['code']) ? $_GET['code'] : ''; // Define regular expression pattern for validation $pattern = "/^([a-f0-9]{8})-(([a-f0-9]{4})-){3}([a-f0-9]{12})$/i"; // Trim any extra spaces $trimmedCode = trim($code); // Validate the format of the purchase code if (!preg_match($pattern, $trimmedCode)) { if (preg_match("/\s+/", $code)) { // Handle whitespace issues http_response_code(403); echo json_encode([ "error" => 403, "message" => "Invalid code format with leading or trailing whitespace" ]); } else { // Handle format error http_response_code(403); echo json_encode([ "error" => 403, "message" => "Code format is incorrect (error code: 1020)" ]); } die; } // Handle valid purchase codes if ($trimmedCode === "86781236-23d0-4b3c-7dfa-c1c147e0dece") { header('Content-Type: application/json; charset=utf-8'); echo json_encode([ "status" => "success", "amount" => "19.84", "sold_at" => "2016-09-07T10:54:28+10:00", "license" => "Regular License", "support_amount" => "0.00", "supported_until" => "2017-03-09T01:54:28+11:00", "item" => [ "id" => 17022701, "name" => "SEO Studio - Professional Tools for SEO", "author_username" => "baileyherbert", "updated_at" => "2017-11-02T15:57:41+11:00", "site" => "codecanyon.net", "price_cents" => 2000, "published_at" => "2016-07-13T19:07:03+10:00" ], "buyer" => "test", "purchase_count" => 1 ]); } // Handle invalid purchase codes else { http_response_code(404); echo json_encode([ "status" => "error", "error_code" => 404, "description" => "No sale found for the provided code." ]); }
Test Case | Request URL | Expected Response |
---|
Valid Code | http://localhost/api.php?code=86781236-23d0-4b3c-7dfa-c1c147e0dece | JSON with sale information. |
Invalid Code | http://localhost/api.php?code=94252c00-df24-4cf5-99dd-49fc17e23043 | JSON with a 404 error message. |
Improper Code | http://localhost/api.php?code=02b6429f-9274-9a70-03ce49bc5a48 | JSON with a 403 error message. |
Code with Leading Whitespace | http://localhost/api.php?code= 86781236-23d0-4b3c-7dfa-c1c147e0dece | JSON with a 403 error message for whitespace. |
Code with Trailing Whitespace | http://localhost/api.php?code=86781236-23d0-4b3c-7dfa-c1c147e0dece | JSON with a 403 error message for whitespace. |