Here is my code to select order report from amazon using mws feed api.This is working fine,but now it returns all _GET_ORDERS_DATA_ type reports,but i only need to get the reports having status _DONE_.is it possible to do with PHP?
Here i found an option for ReportProcessingStatusList but i unable to set with this SDk,how to set this option?
$parameters = array (
'Merchant' => MERCHANT_ID,
'MaxCount' => 100
);
$request = new MarketplaceWebService_Model_GetReportRequestListRequest($parameters);
$TypeList = new MarketplaceWebService_Model_TypeList();
$TypeList->setType('_GET_ORDERS_DATA_');
$request->setReportTypeList($TypeList);
First, you are calling GetReportRequestList, which is part of the Reports API, not Feeds API. You can limit results to a specific report type by requesting the list like this:
$request = new MarketplaceWebService_Model_GetReportRequestListRequest(array(
"ReportProcessingStatusList.Status.1": "_DONE_"
));
By the way, besides the API reference documentation, the Scratchpad helps a lot finding and testing out parameters: https://mws.amazonservices.com/scratchpad/index.html (use the proper URL that matches your country/region)
Related
I am struggling, literally, trying to figure out how to use th Ebay API in order to retrieve the orders received on a specific merchant account and then store some datas in an external DB.
I have registered to developer.ebay.it, I have built a key pair, both for production and sandbox, then I have tried the api (Browse/getItem)...and then...LOST.
I cannot use the Fullfillment, because I always get a response of Insufficient authorization, even if I create a token, even if I put a real order number... I don't get how to question the API.
Lastly, I am using PHP and I have downloaded the davidtsadler SDK from github. How do I configure an example of getOrder with that SDK? Do you have any link, suggestions, anything?
What I find on internet is not enough clear for my level of knowledge and almost nobody deals with the getOrder call.
Thank you for your help.
The ebay API documentation is fairly clear on how to perform a query:
If you wanted to get a specific Fullfillment policy, then you would need to perform a GET request to ebays Fullfillment API using the /order/{orderId} path - where {orderId} is a real order ID.
In PHP, that might go a little something like this:
/* Returns a JSON object containing an ebay order */
function getOrder($order_id, $auth_key){
$options = array(
'http' => array(
'method' => "GET",
'header' => "Authorization: Bearer ".$auth_key."\r\n" .
"Content-Type: application/json"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.ebay.com/sell/fulfillment/v1/order/".$order_id, false, $context);
return json_decode($result);
}
Then you could call the method above and retrieve an order using:
$order = getOrder("A REAL ORDER ID", "YOUR AUTH KEY");
The $order variable now holds a JSON object. You can print info from the object using: (This example prints the username associated with the order)
echo $order->buyer->username;
Finally, please note the direct quote from ebays documentation:
"eBay creates and displays an Application token. This token is valid for a limited time span. If you get an invalid token error when you make a call using this token, simply create a new token and use the new token in your call."
This is the sample code that I am using to get my contacts from Google People API. Works fine.
$people_service = new Google_Service_PeopleService($client); // TODO: Use service object to request People data
$connections = $people_service->people_connections->listPeopleConnections ('people/me',
array('personFields' => 'names,emailAddresses,biographies',
'pageSize' => 25,
'sortOrder' => 'FIRST_NAME_ASCENDING',
));
But I couldn't figure out how to list and manage Contact Groups (like friends, family etc.).
This is the code I am trying without success.
$groups_list = $people_service->contactGroups->listcontactGroups();
Sources I could find:
https://developers.google.com/resources/api-libraries/documentation/people/v1/php/latest/class-Google_Service_PeopleService.html
https://developers.google.com/people/api/rest/v1/contactGroups/list
Have you check if you need to call an extra function as indicated in this documentation? Follow the PHP sample for printing the names for up to 10 connections.
$groups_list = $people_service->contactGroups->listcontactGroups();
$group_list->getContactGroups( );
What I'm trying to currently do is fetch Campaign statistics such as Clicks, Impressions, CTR, Average CPC and etc for a particular campaign. Unfortunately, I can't find how to do it via the AdWords API.
What I've found up till now is that,
Maybe, in an earlier version of the CampaignService, we were able to obtain stats by doing something like $campaign->campaignStats. Unluckily, I'm using V201506 and in it there is no campaignStats object/variable.
I probably can get these stats using the 'CAMPAIGN_PERFORMANCE_REPORT' but it needs to be downloaded and I don't want to download the report. I just want an array or something similar returned so that I can process it. Also, I don't want to give any time frame, I just want all time stats to be returned for that campaign. Is it even possible?
If any one could help me out, I would really appreciate it. Kind of been stuck here for a few hours, skimmed through the whole AdWords API documentation but couldn't understand what would be the best and easy approach to this.
Now, Adwords API allowing stats only By reporting service.
And stats can be get using two methods.
1) By using reporting service as described
here
2) You can use Adwords Query Language. See
this
i don't know if you still need this but the API V201806 I found a solution. In this version of API exist the function getAsString() which returns the data in String and not download file, I request data in format XML and in PHP transform the response into a XML Object.
This is code I used:
class DownloadCriteriaReportWithAwql {
public static function runExample(AdWordsSession $session, $reportFormat){
// Create report query to get the data for last 7 days.
$query = (new ReportQueryBuilder())
->select([
'CampaignId',
'AdGroupId',
'Id',
'Criteria',
'CriteriaType',
'Impressions',
'Clicks',
'Cost',
'Conversions'
])
->from(ReportDefinitionReportType::CRITERIA_PERFORMANCE_REPORT)
->where('Status')->in(['ENABLED'])
->duringDateRange(ReportDefinitionDateRangeType::LAST_7_DAYS)
->build();
// Download report as a string.
$reportDownloader = new ReportDownloader($session);
// Optional: If you need to adjust report settings just for this one
// request, you can create and supply the settings override here.
// Otherwise, default values from the configuration
// file (adsapi_php.ini) are used.
$reportSettingsOverride = (new ReportSettingsBuilder())->includeZeroImpressions(false)->build();
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
sprintf('%s', $query),
$reportFormat,
$reportSettingsOverride
);
//print "Report was downloaded and printed below:\n";
$datos = $reportDownloadResult->getAsString();
return ($datos);
}
public static function main(){
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
// See: AdWordsSessionBuilder for setting a client customer ID that is
// different from that specified in your adsapi_php.ini file.
// Construct an API session configured from a properties file and the
// OAuth2 credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$string = self::runExample($session, DownloadFormat::XML);
$xml = new \SimpleXMLElement($string);
return $xml;}}
The question was asked in 2015, since then they renamed the API to Google Ads API. The current version is V6 where getting clicks, CTR, CPC and other metrics is relatively simple.
The documentation here states:
This page shows all metrics and segments that can be put in the same SELECT clause as the fields of campaign
Based on that the AWQL for getting campaign together with clicks will look like this (tested):
$query = "SELECT campaign.id, campaign.name, campaign.status, metrics.clicks FROM campaign ORDER BY campaign.name"
Example in PHP how to iterate through results:
$stream = $googleAdsServiceClient->searchStream($customerId, $query);
foreach ($stream->iterateAllElements() as $googleAdsRow) {
/** #var GoogleAdsRow $googleAdsRow */
$data['campaigns'][] = [
'id' => $googleAdsRow->getCampaign()->getId(),
'clicks' => $googleAdsRow->getMetrics()->getClicks(),
];
}
I'm a php programmer but I'm new to APIs.
I would like to run a mysql query to get info from an XML document from madmimi.com.
documentation from madmimi.com says
GET http://madmimi.com/audience_lists/lists.xml will return the data I need. I've created a php file and connected to their API using
require(dirname(FILE) . '/MadMimi.class.php');
$mailer = new MadMimi('username', 'password');
but I don't understand how to use GET to connect to the URL and display the XML info?
What do I need to do?
All http api interaction is hidden to you behind their library. You can use it's methods to grab objects, like this to lists:
$mailer->Lists();
There is no complete documentation, but you can read raw code to search urls, described in API for finding appreciated methods.
You can use curl to get the response from the 3rd party api. Have a look at this answer:
https://stackoverflow.com/a/5159513/1369567
Based upon the code in answer given at that link, you may need to the code to match your request. E.g:
/* Script URL */
$url = 'http://madmimi.com/audience_lists/lists.xml';
/* $_GET Parameters to Send */
$params = array('username' => '*your api username*', 'password' => '*your api password*');
I am using Amazon MWS Reports API to get customer's feedback using "_GET_SELLER_FEEDBACK_DATA_" report type.
But unfortunately it says "report status cancelled". Using Scratchpad to request this report it works fine.
The following is my code:
$report_type = "_GET_SELLER_FEEDBACK_DATA_";
$config = array(
'ServiceURL' => "https://mws.amazonservices.co.uk",
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $config, $APPLICATION_NAME, $APPLICATION_VERSION);
$marketplaceIdArray = array("Id" => array($MARKETPLACE_ID));
//Sends Report Request
$request = new MarketplaceWebService_Model_RequestReportRequest();
$request->setMarketplaceIdList($marketplaceIdArray);
$request->setMerchant($MERCHANT_ID);
$request->setReportType($report_type);
$request->setReportOptions('ShowSalesChannel=true');
$request->setStartDate(new DateTime('-90 Days', new DateTimeZone('UTC')));
$report_request_id = invokeRequestReport($service, $request);
The Reports API class methods invokeReportRequest(), invokeGetReportRequestList(), invokeGetReportList() and invokeGetReport() are unchanged by me.
Amazon accepts your report request, but then refuses to actually produce one. I'm not sure if there is a way to get any meaningful error message out of MWS, but from past experience, this kind of thing happens when your request is technically valid but has a logical error of some sorts (e.g. You submit an XML file that validates against the XSD but contains prices for items that are not part of your inventory)
I haven't tested this, but looking at the API docs (MWS Reports API Reference pg. 46), it seems that ShowSalesChannel is not a valid ReportOption for _GET_SELLER_FEEDBACK_DATA_ reports (it seems to be allowed only in order reports, and getting seller feedback does not support any ReportOption). So please try and remove
$request->setReportOptions('ShowSalesChannel=true');
from your code and see what happens.