Using prosperent.com API with PHP!


Currently I am working with Prosperent.com’s affiliate network and making an auto blog plugin for wordpress. The plugin is intended to fetch products from prosperent and create wordpress posts. You will earn commission from the sales through your affiliate link! The affiliate links will also be given by prosperent. So, you don’t need to think about it. You just need to requests their API with the API Key and they will mask the product URL with your affiliate ID so the impressions and clicks are accounted under your affiliate account.

Prosperent already provides a simple and beautiful PHP class that makes enjoyable while working with their API. You just need to write a few lines to get products from them.

Let’s jump to coding. However, first of all you will need to get the API Key. To get the API Key, you have to open an Affiliate account. Then from the control panel, click the menu API -> API Keys -> Add New API Key. It will ask for the name and once you provide such, an API key will be created for you. Note it down as we will need it momentarily.

Now you need to download their PHP wrapper class. There is another submenu under the API menu titled “Prosperent API PHP Class“. Click there and then click Download.

Now use the following code to search products.

require_once('Prosperent_Api.php');
$api_key = 'API_KEY_HERE';

$prosperent = new Prosperent_Api(array(
    'api_key'       =>      $api_key,
    'visitor_ip'    =>      '127.0.0.1',
    'page'          =>      1,
    'limit'         =>      5,
));
$prosperent->set_debugMode(true);

We just have initialized our prosperent object. For a search request, 3 parameters are required. Those are API Key, Visitor’s IP and Search Query. So far we have provided API Key and IP. We will now feed the object our search query.

$prosperent->set_query('dell');

So, we have set the query we want to search for. Now we need to trigger the method to get results for us.

$prosperent->fetch();

Now we should check if the API returned any error or not! Errors need to resolve first before going further operations!

if($prosperent->hasErrors()){
    echo '<pre>';
    print_r($prosperent->getErrors());
    echo '<pre>';
}

Optionally, you can also check if any warnings are given!

if($prosperent->hasWarnings()){
    echo '<pre>';
    print_r($prosperent->getWarnings());
    echo '<pre>';
}

Let’s assume we were angel and did not make any mistakes. So, its time to get our data.

$products = $prosperent->getData();
if(count($products)){
    foreach($products as $product){
        echo '<pre>';
        print_r($product);
        echo '</pre>';
    }
}

See output? If so, it is good. We got the products in the $product array. Now you can play with it! If you now want to search for another keyword, you don’t need to reinitialize the object. You just start from set_query method.

$prosperent->set_query('console');
$prosperent->fetch();
if($prosperent->hasErrors()){
    echo '<pre>';
    print_r($prosperent->getErrors());
    echo '<pre>';
}

$products = $prosperent->getData();
if(count($products)){
    foreach($products as $product){
        echo '<pre>';
        print_r($product);
        echo '</pre>';
    }
}

It’s simple. Isn’t it? Next I will try to discuss how to dynamically search for products based on SERP Keyword!