PDA

View Full Version : Trends Data



enzeder
12-14-2011, 07:06 AM
Is there something wrong with the trends data at the moment, or has something changed ?

I have a script I wrote based on the one Andrew posted a while ago that has been returning data just fine, then all of a sudden I am not getting any data returned at all, not even any errors. Hard to debug when I cannot see anything.

prosperent brian
12-14-2011, 07:45 AM
Nothing has been changed or updated. We use data from trends on theNetPool, and it still displays normally as well.

enzeder
12-14-2011, 08:04 AM
Thanks, I'll start digging deeper.

prosperent brian
12-14-2011, 08:09 AM
If you post up your code, one of the guys can likely see if there is anything that would prevent it from working properly.

enzeder
12-14-2011, 08:41 AM
Here is my test script. It just takes a starting date, ending date and merchant name, and returns trend data. I use the guts of this script to return trends data on some other sites, but even this test script will not return anything right now, whereas it used to. I have tried various popular merchants like zappos, 6pm etc. Using latest version of API in Prosperent_Api.php include file 2.0.4



<?php

//ini_set('display_errors',1);
//error_reporting(E_ALL);

$datestart=$_GET['datestart'];
$dateend=$_GET['dateend'];
$merch=$_GET['merch'];

echo "<form><p>";
echo "Starting Date yyyymmdd : <input type='text' name='datestart' value='$datestart'><br>";
echo "Ending Date yyyymmdd: <input type='text' name='dateend' value='$dateend'><br>";
echo "Merchant Name: <input type='text' name='merch' value='$merch'><br>";
echo "<input type='submit' name='Submit' value='----- Submit -----'>";
echo "</p></form>";


require_once('Prosperent_Api.php');


$prosperentApi = new Prosperent_Api(array(
'filterMerchant' => $merch,
'commissionDateRange' => $datestart,$dateend
));

//fetch the result
$prosperentApi->fetchTrends();

//iterate through the facets response
echo '<table border="1">';
$i=0;
foreach ($prosperentApi->getFacets('keyword') as $row)
{
/*
* if this is the first row, set the titles
*/
if ($i++ == 0)
{
echo '<tr>';

foreach (array_keys($row) as $th)
{
echo '<th>' . $th . '</th>';
}

echo '</tr>';
}

echo '<tr>';

foreach ($row as $value)
{
echo '<td>' . substr($value, 0, 50) . '</td>';
}

echo '</tr>';
}
echo '</table>';

?>



Also is there a way using the API this way that I can limit results. I don;t need the full 100 that are usually returned.

Thanks.

Prosperent Andrew
12-14-2011, 10:02 AM
Replace


'commissionDateRange' => $datestart,$dateend

with


'commissionDateRange' => $datestart . ',' . $dateend


Don't forget the dates must be in Ymd format, for example, '20111201'

Prosperent Mike
12-14-2011, 10:08 AM
There is an easier method you can use that simplifies the passing of your start and end date:



$prosperentApi->setDateRange('commission', 20111201, 20111214);
$prosperentApi->fetchTrends();


Or, alternatively, if you want the end date to be yesterday without having to define it, simply set your start date and skip the third argument:



$prosperentApi->setDateRange('commission', 20111201);
$prosperentApi->fetchTrends();


This method also works for the click date range. Simply change the first argument to 'click':



$prosperentApi->setDateRange('click', 20111201);
$prosperentApi->fetchTrends();

enzeder
12-14-2011, 11:46 AM
Thanks Andrew and Mike, made the change to the commissionDateRange:


'commissionDateRange' => $datestart . ',' . $dateend

putting the comma in quotes, but still not working. It has been working fine with it as it was until a couple of days ago.

Also just copied it and the APi file across to another server and ran it, same result, no results. Also no errors in log files.

Here is the updated script copied straight form the server:


<?php

//ini_set('display_errors',1);
//error_reporting(E_ALL);

$datestart=$_GET['datestart'];
$dateend=$_GET['dateend'];
$merch=$_GET['merch'];

echo "<form><p>";
echo "Starting Date yyyymmdd : <input type='text' name='datestart' value='$datestart'><br>";
echo "Ending Date yyyymmdd: <input type='text' name='dateend' value='$dateend'><br>";
echo "Merchant Name: <input type='text' name='merch' value='$merch'><br>";
echo "<input type='submit' name='Submit' value='----- Submit -----'>";
echo "</p></form>";


require_once('Prosperent_Api.php');


$prosperentApi = new Prosperent_Api(array(
'filterMerchant' => $merch,
'commissionDateRange' => $datestart.','.$dateend
));

//fetch the result
$prosperentApi->fetchTrends();

//iterate through the facets response
echo '<table border="1">';
$i=0;
foreach ($prosperentApi->getFacets('keyword') as $row)
{
/*
* if this is the first row, set the titles
*/
if ($i++ == 0)
{
echo '<tr>';

foreach (array_keys($row) as $th)
{
echo '<th>' . $th . '</th>';
}

echo '</tr>';
}

echo '<tr>';

foreach ($row as $value)
{
echo '<td>' . substr($value, 0, 50) . '</td>';
}

echo '</tr>';
}
echo '</table>';

?>

Prosperent Mike
12-14-2011, 05:01 PM
Ah, I see it now. It's because you're trying to get the keyword facet from trends. We removed that facet from all endpoints except the catalog endpoint (which will also lose the keyword facet on Jan 1). It's easier to use the productId or catalogId to get the keyword data.

enzeder
12-14-2011, 05:04 PM
Ahh, thanks Mike, no wonder I couldn't figure it out :)

enzeder
12-14-2011, 05:09 PM
So to get the actual products now, we would have to take the productId or catalogId and look those up with another API request ? or is there a shortcut I am missing.

Prosperent Brandon
12-15-2011, 08:10 AM
Yea, depending on what you want returned, productId will return all products from merchants with that productId, whereas catalogId will return one product since it is a unique identifier.

Taken out of the API documentation:
A product ID is a non-unique identifier for a product that can be available from multiple merchants.
A catalog ID is a unique identifier for a specific record in our catalog.

enzeder
12-15-2011, 09:46 AM
Thanks Brandon, got it all working again. I'm using catalogId, then doing a second API query to gt the data back for each catalogId.

Prosperent Mike
12-15-2011, 10:27 AM
Brandon hit the nail on the head, thanks Brando! Sorry, I was delayed in getting back to you, enzeder