PHP code example of jootop / amazon-advertising-api-php-sdk

1. Go to this page and download the library: Download jootop/amazon-advertising-api-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jootop / amazon-advertising-api-php-sdk example snippets


$client->registerProfile(array("countryCode" => "IT"));


namespace AmazonAdvertisingApi;

LIENT_ID",
    "clientSecret" => "CLIENT_SECRET",
    "refreshToken" => "REFRESH_TOKEN",
    "region" => "na",
    "sandbox" => false,
  );

$client = new Client($config);

$request = $client->doRefreshToken();

$request = $client->listProfiles();

$client->profileId = "1234567890";

$client->getProfile("1234567890");

$client->updateProfiles(
   array(
       array(
           "profileId" => $client->profileId,
           "dailyBudget" => 3.99),
       array(
           "profileId" => 11223344,
           "dailyBudget" => 6.00)));


$request = $client->getPortfolio(1234567890);

$request = $client->getPortfolioEx(1234567890);

$request = $client->createPortfolios($data);

$request = $client->updatePortfolios($data);

$request = $client->listPortfolios(array("portfolioStateFilter" => "enabled"));

#listPortfoliosEx
$request = $client->listPortfoliosEx();

$client->listCampaigns(array("stateFilter" => "enabled"));

$client->getCampaign(1234567890);

$client->listCampaignsEx(array("stateFilter" => "enabled"));

$client->createCampaigns(
    array(
        array("name" => "My Campaign One",
              "campaignType" => "sponsoredProducts",
              "targetingType" => "manual",
              "state" => "enabled",
              "dailyBudget" => 5.00,
              "startDate" => date("Ymd")),
        array("name" => "My Campaign Two",
              "campaignType" => "sponsoredProducts",
              "targetingType" => "manual",
              "state" => "enabled",
              "dailyBudget" => 15.00,
              "startDate" => date("Ymd"))));

$client->updateCampaigns(
    array(
        array("campaignId" => 173284463890123,
              "name" => "Update Campaign One",
              "state" => "enabled",
              "dailyBudget" => 10.99),
        array("campaignId" => 27074907785456,
              "name" => "Update Campaign Two",
              "state" => "enabled",
              "dailyBudget" => 99.99)));

$client->archiveCampaign(1234567890);

$client->listAdGroups(array("stateFilter" => "enabled"));

$client->listAdGroupsEx(array("stateFilter" => "enabled"));

$client->getAdGroup(262960563101486);

$client->createAdGroups(
    array(
        array(
            "campaignId" => 250040549047739,
            "name" => "New AdGroup One",
            "state" => "enabled",
            "defaultBid" => 2.0),
        array(
            "campaignId" => 59836775211065,
            "name" => "New AdGroup Two",
            "state" => "enabled",
            "defaultBid" => 5.0)));

$client->updateAdGroups(
    array(
        array(
            "adGroupId" => 117483076163518,
            "state" => "enabled",
            "defaultBid" => 20.0),
        array(
            "adGroupId" => 123431426718271,
            "state" => "enabled",
            "defaultBid" => 15.0)));

$client->archiveAdGroup(117483076163518);

$client->listBiddableKeywords(array("stateFilter" => "enabled"));

$client->listBiddableKeywordsEx(array("stateFilter" => "enabled"));

$client->getBiddableKeyword(174140697976855);

$client->createBiddableKeywords(
    array(
        array(
            "campaignId" => 250040549047739,
            "adGroupId" => 52169162825843,
            "keywordText" => "AnotherKeyword",
            "matchType" => "exact",
            "state" => "enabled"),
        array(
            "campaignId" => 250040549047739,
            "adGroupId" => 52169162825843,
            "keywordText" => "YetAnotherKeyword",
            "matchType" => "exact",
            "state" => "enabled")));

$client->updateBiddableKeywords(
       array(
           array(
               "keywordId" => 112210768353976,
               "bid" => 100.0,
               "state" => "archived"),
           array(
               "keywordId" => 249490346605943,
               "bid" => 50.0,
               "state" => "archived")));

$client->archiveBiddableKeyword(112210768353976);

$client->listNegativeKeywords(array("stateFilter" => "enabled"));

$client->listNegativeKeywordsEx(array("stateFilter" => "enabled"));

$client->getNegativeKeyword(281218602770639);

$client->createNegativeKeywords(
    array(
        array(
            "campaignId" => 250040549047739,
            "adGroupId" => 52169162825843,
            "keywordText" => "AnotherKeyword",
            "matchType" => "negativeExact",
            "state" => "enabled"),
        array(
            "campaignId" => 181483024866689,
            "adGroupId" => 262960563101486,
            "keywordText" => "YetAnotherKeyword",
            "matchType" => "negativeExact",
            "state" => "enabled")));

$client->updateNegativeKeywords(
       array(
           array(
               "keywordId" => 61857817062026,
               "state" => "enabled",
               "bid" => 15.0),
           array(
               "keywordId" => 61857817062026,
               "state" => "enabled",
               "bid" => 20.0)));

$client->archiveNegativeKeyword(61857817062026);

$client->listCampaignNegativeKeywords(array("matchTypeFilter" => "negativeExact"));

$client->getCampaignNegativeKeyword(197201372210821);

$client->createCampaignNegativeKeywords(
       array(
           array(
               "campaignId" => 181483024866689,
               "keywordText" => "Negative Keyword One",
               "matchType" => "negativeExact",
               "state" => "enabled"),
           array(
               "campaignId" => 181483024866689,
               "keywordText" => "Negative Keyword Two",
               "matchType" => "negativeExact",
               "state" => "enabled")));

$client->removeCampaignNegativeKeyword(186203479904657);

$client->listProductAds(array("stateFilter" => "enabled"));

$client->listProductAdsEx(array("stateFilter" => "enabled"));

$client->getProductAd(247309761200483);

$client->createProductAds(
    array(
        array(
            "campaignId" => 181483024866689,
            "adGroupId" => 262960563101486,
            "sku" => "TEST002",
            "state" => "enabled"),
        array(
            "campaignId" => 181483024866689,
            "adGroupId" => 262960563101486,
            "sku" => "TEST003",
            "state" => "enabled")));

$client->updateProductAds(
    array(
        array(
            "adId" => 239870616623537,
            "state" => "archived"),
        array(
            "adId" => 191456410590622,
            "state" => "archived")));

$client->archiveProductAd(239870616623537);

$client->getTargetingClause(123456789);

$client->listTargetingClauses(array('stateFilter'=>'enabled'));

$client->getTargetingClauseEx(123456789);

$client->listTargetingClausesEx(array('stateFilter'=>'enabled'));

$client->createTargetingClauses(array(array(
"campaignId"=> 127985268700344,
    "adGroupId"=> 456789012345,
    "expressionType"=> "manual",
    "expression"=> array(
        "type"=> "asinCategorySameAs",
        "value"=> "12345567"
    ),
    "bid"=> 10,
    "state"=> "enabled"
)));

$client->updateTargetingClauses(array(array(
"campaignId"=> 127985268700344,
    "adGroupId"=> 456789012345,
    "targetId"=> 123452234567,
    "expressionType"=> "manual",
    "expression"=> array(
        "type"=> "asinCategorySameAs",
        "value"=> "12345567"
    ),
    "bid"=> 10,
    "state"=> "enabled"
)));

$client->archiveTargetingClause(123456789);

$client->getTargetingCategories(array('asins'=>'ASDF,EFGH,DSFDSK'));

$client->getBrandRecommendations(array('categoryId'=>123456789));

$client->getNegativeTargetingClause(123456789);

$client->getNegativeTargetingClauseEx(123456789);

$client->createNegativeTargetingClauses(array(array(
    "campaignId"=> 127985268700344,
        "adGroupId"=> 456789012345,
        "targetId"=> 123452234567,
        "expressionType"=> "manual",
        "expression"=> array(
            "type"=> "asinCategorySameAs",
            "value"=> "12345567"
        ),
        "bid"=> 10,
        "state"=> "enabled"
    )));

$client->listNegativeTargetingClauses(array('stateFilter'=>'enabled'));

$client->listNegativeTargetingClausesEx(array('stateFilter'=>'enabled'));

$client->archiveNegativeTargetingClause(123456789);

$client->updateNegativeTargetingClauses(array(array(
   "campaignId"=> 127985268700344,
       "adGroupId"=> 456789012345,
       "targetId"=> 123452234567,
       "expressionType"=> "manual",
       "expression"=> array(
           "type"=> "asinCategorySameAs",
           "value"=> "12345567"
       ),
       "bid"=> 10,
       "state"=> "enabled"
   )));

$client->requestSnapshot(
    "campaigns",
    array("stateFilter" => "enabled,paused,archived",
          "campaignType" => "sponsoredProducts"));

$client->getSnapshot("amzn1.clicksAPI.v1.p1.573A0477.ec41773a-1659-4013-8eb9-fa18c87ef5df");

$client->requestReport(
    "campaigns",
    array("reportDate" => "20160515",
          "campaignType" => "sponsoredProducts",
          "metrics" => "impressions,clicks,cost"));

$client->getReport("amzn1.clicksAPI.v1.m1.573A0808.32908def-66a1-4ce2-8f12-780dc4ae1d43");

$client->getAdGroupBidRecommendations(1234509876);

$client->getKeywordBidRecommendations(85243141758914);

$client->bulkGetKeywordBidRecommendations(
    242783265349805,
    array(
        array("keyword" => "testKeywordOne",
              "matchType" => "exact"),
        array("keyword" => "testKeywordTwo",
              "matchType" => "exact")
    ));

$client->getAdGroupKeywordSuggestions(
    array("adGroupId" => 1234567890,
          "maxNumSuggestions" => 2,
          "adStateFilter" => "enabled"));

$client->getAdGroupKeywordSuggestionsEx(
    array("adGroupId" => 1234567890,
          "maxNumSuggestions" => 2,
          "suggestBids" => "yes",
          "adStateFilter" => "enabled"));

$client->getAsinKeywordSuggestions(
    array("asin" => "B00IJSNPM0",
          "maxNumSuggestions" => 2));

$client->bulkGetAsinKeywordSuggestions(
    array("asins" => array(
              "B00IJSNPM0",
              "B00IJSO1NM"),
          "maxNumSuggestions" => 2));