Join Free
  • Trends: Top 20 Products Example

    The example code below queries the trends api endpoint for the top 20 shoe related products. We then loop through the results, grab the image, description, url and such from the product api and output the results as html. Copy and paste the below code snippet into a file, add your api key, and upload our php api class to view the example.

    PHP Code:
    <?php
    //Trends Limit for top sellers
    $trendLimit '20'

    //Todays Date ymd used for trends query
    $today date("Ymd"); 

    //API Key
    $apiKey 'INSERT YOUR API KEY';

    //Setup Query Parameters
    require_once('Prosperent_Api.php'); 
    $prosperentApi = new Prosperent_Api(array( 
            
    'filterKeyword'      =>  '*shoe*',
            
    'commissionDateRange' => '20130101,' $today,
            
    'enableFacets' => 'productId'
        
    )); 


        
    //fetch the result 
        
    $prosperentApi->fetchTrends(); 
        foreach (
    $prosperentApi->getFacets('productId') as $productId
        { 
        
    $productArray[] = $productId['value'];
        }
        require_once(
    'Prosperent_Api.php');
        
    $prosperentApi = new Prosperent_Api(array(
          
    'api_key'         => $apiKey,
          
    'filterProductId' => $productArray,
          
    'visitor_ip'      => $_SERVER['REMOTE_ADDR'],
          
    'channel_id'      => 0,
          
    'page'            => 1,
          
    'imageSize'       => '125x125',
          
    'limit'           => $trendLimit  
      
    )); 
      
    //Loop Through Results and Output to Page 
    $results $prosperentApi->fetch();
    foreach (
    $prosperentApi->getData() as $record
        { 
    ?>
        <li id="serp2" class="result "  >
          <div class="result-body">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="125px"><div style="width: 125px; height: 125px; overflow: hidden;"><a class="UrlTitleLine ui-widget-content "  
    href="<?=$record['affiliate_url']?>" dest="<?=$record['affiliate_url']?>" orig="<?=$record['affiliate_url']?>" pos="1"
    title="<?=$record['keyword']?>" ><img
     src="<?=$record['image_url']?>"  alt="<?=$record['keyword']?>" title="<?=$record['keyword']?>" width=125 height=125></a></div></td>
              </tr>
            </table>
            <div class="url-line"> <span class="resultUrl ">
              <?=$record['merchant']?>
              </span> <span class="non-url"> &nbsp;&nbsp;&ndash;&nbsp; $
              <?=$record['price']?>
              &nbsp;
              <?=$record['brand']?>
              </span>
              <div id="tools1" class="pop-shadow-small round5 tools-pop"></div>
            </div>
          </div>
        </li>
        <?php
    }  
    ?>
    Comments 8 Comments
    1. Prospekim's Avatar
      Any ideas why I'm getting these notices?

      Notice: Undefined index: query in /Prosperent_Api.php on line 2727 Notice: Undefined index: cacheBackend in /Prosperent_Api.php on line 562 Notice: Use of undefined constant endpoint - assumed 'endpoint' in /Prosperent_Api.php on line 745 Notice: Undefined property: Prosperent_Api::$_cacheKey in /Prosperent_Api.php on line 989 Notice: Undefined index: dataKeys in /Prosperent_Api.php on line 1089 Notice: Undefined index: couponsKeys in /Prosperent_Api.php on line 1089 Notice: Undefined index: imageBaseUrls in /Prosperent_Api.php on line 1113 Notice: Undefined index: data in /Prosperent_Api.php on line 1116 Notice: Undefined index: coupons in /Prosperent_Api.php on line 1117 Notice: Undefined index: query in /Prosperent_Api.php on line 2727 Notice: Undefined index: cacheBackend in /Prosperent_Api.php on line 562 Notice: Use of undefined constant endpoint - assumed 'endpoint' in /Prosperent_Api.php on line 745 Notice: Undefined property: Prosperent_Api::$_cacheKey in /Prosperent_Api.php on line 989 Notice: Undefined index: couponsKeys in /Prosperent_Api.php on line 1089 Notice: Undefined index: facetsKeys in /Prosperent_Api.php on line 1089 Notice: Undefined offset: 0 in /Prosperent_Api.php on line 669 Notice: Undefined index: query in /Prosperent_Api.php on line 2727 Notice: Undefined index: keyword in /Prosperent_Api.php on line 1622

      The html on the page comes out like this:
      <div class="result-body">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td width="125px"><div style="width: 125px; height: 125px; overflow: hidden;"><a class="UrlTitleLine ui-widget-content "
      href="<?=$record['affiliate_url']?>" dest="<?=$record['affiliate_url']?>" orig="<?=$record['affiliate_url']?>" pos="1"
      title="<?=$record['keyword']?>" ><img
      src="<?=$record['image_url']?>" alt="<?=$record['keyword']?>" title="<?=$record['keyword']?>" width=125 height=125></a></div></td>
      </tr>
      </table>
      <div class="url-line"> <span class="resultUrl ">
      <?=$record['merchant']?>
      </span> <span class="non-url"> &nbsp;&nbsp;&ndash;&nbsp; $
      <?=$record['price']?>
      &nbsp;
      <?=$record['brand']?>
      </span>
      <div id="tools1" class="pop-shadow-small round5 tools-pop"></div>
      </div>
      </div>
    1. prosperent brian's Avatar
      Are you using the latest php api class that we have for download?
    1. Prospekim's Avatar
      Yes I am...
    1. Hoops2's Avatar
      Did you just upgrade to PHP 5.4 or install on new hosting? You don't need to worry about notices. Change your error reporting in your php.ini
    1. Prospekim's Avatar
      I upgraded to php 5.4 from 5.2, and then downgraqded to 5.3.23 when I realized zend didn't work with 5.4.
      I don't worry about notices, I actually just enabled them to see what was going on.

      I will give it a try on another server.
    1. Prospekim's Avatar
      I'm getting the exact same on another server.
    1. prosperent brian's Avatar
      Can't really say without seeing an example. You might need to enable short open tags in your php.ini.
    1. Prospekim's Avatar
      Quote Originally Posted by prosperent brian View Post
      You might need to enable short open tags in your php.ini.
      That was the problem
      Thanks!
coupons | coupons and deals