how to get report data from basic report services like keywordsummarybyday using the yahoo search marketing ysm api in php

Here I present a step by step way to get report data ( from the Yahoo Search Marketing API (YSM). I Give the example to get the report data from the KeywordSummaryByDay.

The yahoo search marketing api based on the SOAP web services. I assume that you have the official client YahooEWSClient.Php. Also you have Production key or Test key information (SandBox account). All of the codes are based on YahooEWSClient.Php.

The steps to get report data are followings :

Details description found (


_STEP 1 : Initialize SOAP clients for a Basic Report Services.

_STEP 2 : Report Request for particular Account Id .

_STEP 3 : Get Report List

_STEP 4 : Get Output Report Url

_STEP 5 : Call the url through http get method

_STEP 1 : Create a Basic Report Service

YSM has many Services. To get report data they provide the BasicReport services.

_STEP 2 : Request a report that aggregates metrics for a specific account. It has 2 parameters .It return a report id.

1. accountID which is a string .

it has 4 elements

· dateRange

· endDate

· reportName

· reportType

· startDate

_STEP3 : Get report list

This step may be you omit. Actually this return the report id which are Complited. It takes a parameter of true/false. If true then return only the completed report id.

_STEP4 : Get Output Report Url

Return a URL that you can use to retrieve the report (specified by reportID) using the HTTP GET method. For security reasons, the URL is available for 5 minutes only.

If the report is not ready, the return string will contain the status of the report rather than the URL.

It takes parameter for 2 .

· Report id

· File format . (FileOutputFormat here you can specify whether you get the data in xml,csv etc format.)

_STEP 5: Call the url through http get method

You can use curl to get the data from url.

Here is a sample code :

$basicReportService =
createClient( EWS_VERSION. “/BasicReportSer vice”, $accountID);

createReport( $basicReportServ ice, $accountID);

//createReport method defined
function createReport( $basicReportServ ice, $accountID)
debug(‘Calling CreateReport’ );
$retObj = execute($basicRepor tService,
‘addReportRequestFo rAccountID’ ,
array(‘accountID’ => $accountID,
‘reportRequest’ => array(‘reportName’ => ‘keyword_summary_ report’,
‘reportType’ => ‘KeywordSummaryByDa y’,
‘dateRange’ => ‘Last7Days’

$reportID = $retObj->out;
debug(“ReportID obtained:”+$ reportID) ;

$reportURL = “”;
$counter = 0;

while ($counter++ < 5) {
$retObj = execute($basicRepor tService,
‘getReportOutputUrl ‘,
array(‘reportID’ => $reportID,
‘fileFormat’ => array(‘fileOutputTy pe’ => ‘CSV’,
‘zipped’ => false
debug(‘reportURL- —‘.$retObj- >out);
if ($retObj->out == ‘PENDING’) {
else {
$reportURL = $retObj->out;
debug(“Waiting for Report URL …”);
sleep(60);// poll interval 60 secs

if($reportURL != ‘PENDING’){

debug(“REPORT URL->”.$reportURL) ;
$downloadLocation = downloadURL
($reportURL, ‘keywordsummaryb yday’,’CSV’ );

For further details you can contact with me.


    • basicreport
    • May 18th, 2009

    Hi I am not receiving the url for some reason.

    116 while (1) {
    117 $retObj = execute($basicReportService,
    118 ‘getReportOutputUrl’,
    119 array(‘reportID’ => $reportID,
    120 ‘fileFormat’ => array(‘fileOutputType’ => ‘XML’,
    121 ‘zipped’ => false
    122 )
    123 )
    124 );
    126 debug(‘reportURL’ . $retObj->out);
    138 $reportURL == $retObj->out;
    139 if($reportURL != ‘PENDING’);
    140 break;
    141 }
    143 if($reportURL != ‘PENDING’){
    144 debug(“REPORT URL->” . $reportURL) ;
    145 }

    any thoughts?

    • saidi samir
    • December 7th, 2009

    merci beaucoup pour votre aide!!
    comment on peu debuguer cette application?
    pour vous informer , j’ai tous ce qui faut pour pouvoir faire des tests sur la sandbox!!
    est ce qu on peux faire la meme chose en c#?

    • saidi samir
    • December 7th, 2009

    do you ca send me an application for testing with my license?
    thank you!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: