imikemiller/amazon-advertising-api-php-sdk

Amazon Advertising API Client Library

1.2 2017-08-28 21:28 UTC

This package is not auto-updated.

Last update: 2024-11-10 05:29:57 UTC


README

Official Amazon Advertising API PHP client library.

Requirements

PHP >= 5.3.0
cURL >= 7.18

Documentation

API Reference
Access Request
Getting Started

Tutorials

Register Sandbox Profile - This tutorial will show you how to register a profile in sandbox using CURL.
Generate and download a report using CURL - You will need to complete registering a profile in sandbox prior to doing this tutorial.

Sandbox self-service

If you would like to test the API in sandbox you will need to register a profile for the region in which you would like to test. The registerProfile API call can be made to do this. Make sure you instantiate the client in sandbox mode before making this call or it will fail.

The following country codes are available for testing.

US, CA, UK, DE, FR, ES, IT, IN, CN, JP

$client->registerProfile(array("countryCode" => "IT"));
{
  "registerProfileId": "5cf1aca5-4ab8-4489-8c33-013d1f85c586JP",
  "status": "IN_PROGRESS",
  "statusDetails": "Registration workflow has been started"
}

Quick Start

Instantiate the client

You can pass in accessToken if you do not have a refresh token.

<?php
namespace AmazonAdvertisingApi;

require_once "AmazonAdvertisingApi/Client.php";

$config = array(
    "clientId" => "CLIENT_ID",
    "clientSecret" => "CLIENT_SECRET",
    "refreshToken" => "REFRESH_TOKEN",
    "region" => "na",
    "sandbox" => false,
  );

$client = new Client($config);

Refresh access token

You can refresh your access token when it expires by using the following method. The new access token will be in the request response. This method will set it for you so it's mainly for reference if you need it.

$request = $client->doRefreshToken();

Get a list of profiles

$request = $client->listProfiles();
[{
  "profileId":1234567890,
  "countryCode":"US",
  "currencyCode":"USD",
  "dailyBudget":10.00,
  "timezone":"America/Los_Angeles",
  "accountInfo":{
  "marketplaceStringId":"ABC123",
  "sellerStringId":"DEF456"
}]

Set profile Id

$client->profileId = "1234567890";

Once you've set the profile Id you are ready to start making API calls.

Example API Calls

getProfile

Retrieves a single profile by Id.

$client->getProfile("1234567890");
{
  "profileId": 1234567890,
  "countryCode": "US",
  "currencyCode": "USD",
  "dailyBudget": 3.99,
  "timezone": "America/Los_Angeles",
  "accountInfo": {
    "marketplaceStringId": "ABC123",
    "sellerStringId": "DEF456"
  }
}

updateProfiles

Updates one or more profiles. Advertisers are identified using their profileIds.

$client->updateProfiles(
   array(
       array(
           "profileId" => $client->profileId,
           "dailyBudget" => 3.99),
       array(
           "profileId" => 11223344,
           "dailyBudget" => 6.00)));
[
  {
    "code": "SUCCESS",
    "profileId": 1234567890
  },
  {
    "code": "NOT_FOUND",
    "description": "Profile with id 11223344 was not found for this advertiser.",
    "profileId": 0
  }
]

listCampaigns

Retrieves a list of campaigns satisfying optional criteria.

$client->listCampaigns(array("stateFilter" => "enabled"));
[
  {
    "campaignId": 59836775211065,
    "name": "CampaignOne",
    "campaignType": "sponsoredProducts",
    "targetingType": "manual",
    "dailyBudget": 15.0,
    "startDate": "20160330",
    "state": "enabled"
  },
  {
    "campaignId": 254238342004647,
    "name": "CampaignTwo",
    "campaignType": "sponsoredProducts",
    "targetingType": "manual",
    "dailyBudget": 5.0,
    "startDate": "20160510",
    "state": "enabled"
  }
]

getCampaign

Retrieves a campaign by Id. Note that this call returns the minimal set of campaign fields, but is more efficient than getCampaignEx.

$client->getCampaign(1234567890);
{
  "campaignId": 1234567890,
  "name": "CampaignOne",
  "campaignType": "sponsoredProducts",
  "targetingType": "manual",
  "dailyBudget": 15.0,
  "startDate": "20160330",
  "state": "enabled"
}

createCampaigns

Creates one or more campaigns. Successfully created campaigns will be assigned unique campaignIds.

$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"))));
[
  {
    "code": "SUCCESS",
    "campaignId": 173284463890123
  },
  {
    "code": "SUCCESS",
    "campaignId": 27074907785456
  }
]

updateCampaigns

Updates one or more campaigns. Campaigns are identified using their campaignIds.

$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)));
[
  {
    "code": "SUCCESS",
    "campaignId": 173284463890123
  },
  {
    "code": "SUCCESS",
    "campaignId": 27074907785456
  }
]

archiveCampaign

Sets the campaign status to archived. This same operation can be performed via an update, but is included for completeness.

$client->archiveCampaign(1234567890);
{
  "code": "SUCCESS",
  "campaignId": 1234567890
}

listAdGroups

Retrieves a list of ad groups satisfying optional criteria.

$client->listAdGroups(array("stateFilter" => "enabled"));
[
  {
    "adGroupId": 262960563101486,
    "name": "AdGroup One",
    "campaignId": 181483024866689,
    "defaultBid": 1.0,
    "state": "enabled"
  },
  {
    "adGroupId": 52169162825843,
    "name": "AdGroup Two",
    "campaignId": 250040549047739,
    "defaultBid": 2.0,
    "state": "enabled"
  }
]

getAdGroup

Retrieves an ad group by Id. Note that this call returns the minimal set of ad group fields, but is more efficient than getAdGroupEx.

$client->getAdGroup(262960563101486);
{
  "adGroupId": 262960563101486,
  "name": "AdGroup One",
  "campaignId": 181483024866689,
  "defaultBid": 1.0,
  "state": "enabled"
}

createAdGroups

Creates one or more ad groups. Successfully created ad groups will be assigned unique adGroupIds.

$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)));
[
  {
    "code": "SUCCESS",
    "adGroupId": 117483076163518
  },
  {
    "code": "SUCCESS",
    "adGroupId": 123431426718271
  }
]

updateAdGroups

Updates one or more ad groups. Ad groups are identified using their adGroupIds.

$client->updateAdGroups(
    array(
        array(
            "adGroupId" => 117483076163518,
            "state" => "enabled",
            "defaultBid" => 20.0),
        array(
            "adGroupId" => 123431426718271,
            "state" => "enabled",
            "defaultBid" => 15.0)));
[
  {
    "code": "SUCCESS",
    "adGroupId": 117483076163518
  },
  {
    "code": "SUCCESS",
    "adGroupId": 123431426718271
  }
]

archiveAdGroup

Sets the ad group status to archived. This same operation can be performed via an update, but is included for completeness.

$client->archiveAdGroup(117483076163518);
{
  "code": "SUCCESS",
  "adGroupId": 117483076163518
}

listBiddableKeywords

Retrieves a list of keywords satisfying optional criteria.

$client->listBiddableKeywords(array("stateFilter" => "enabled"));
[
  {
    "keywordId": 174140697976855,
    "adGroupId": 52169162825843,
    "campaignId": 250040549047739,
    "keywordText": "KeywordOne",
    "matchType": "exact",
    "state": "enabled"
  },
  {
    "keywordId": 118195812188994,
    "adGroupId": 52169162825843,
    "campaignId": 250040549047739,
    "keywordText": "KeywordTwo",
    "matchType": "exact",
    "state": "enabled"
  }
]

getBiddableKeyword

Retrieves a keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than getBiddableKeywordEx.

$client->getBiddableKeyword(174140697976855);
{
  "keywordId": 174140697976855,
  "adGroupId": 52169162825843,
  "campaignId": 250040549047739,
  "keywordText": "KeywordOne",
  "matchType": "exact",
  "state": "enabled"
}

createBiddableKeywords

Creates one or more keywords. Successfully created keywords will be assigned unique keywordIds.

$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")));
[
  {
    "code": "SUCCESS",
    "keywordId": 112210768353976
  },
  {
    "code": "SUCCESS",
    "keywordId": 249490346605943
  }
]

updateBiddableKeywords

Updates one or more keywords. Keywords are identified using their keywordIds.

$client->updateBiddableKeywords(
       array(
           array(
               "keywordId" => 112210768353976,
               "bid" => 100.0,
               "state" => "archived"),
           array(
               "keywordId" => 249490346605943,
               "bid" => 50.0,
               "state" => "archived")));
[
  {
    "code": "SUCCESS",
    "keywordId": 112210768353976
  },
  {
    "code": "SUCCESS",
    "keywordId": 249490346605943
  }
]

archiveBiddableKeyword

Sets the keyword status to archived. This same operation can be performed via an update, but is included for completeness.

$client->archiveBiddableKeyword(112210768353976);
{
  "code": "200",
  "requestId": "0TR95PJD6Z16FFCZDXD0"
}

listNegativeKeywords

Retrieves a list of negative keywords satisfying optional criteria.

$client->listNegativeKeywords(array("stateFilter" => "enabled"));
[
  {
    "keywordId": 281218602770639,
    "adGroupId": 52169162825843,
    "campaignId": 250040549047739,
    "keywordText": "KeywordOne",
    "matchType": "negativeExact",
    "state": "enabled"
  },
  {
    "keywordId": 280875877064090,
    "adGroupId": 262960563101486,
    "campaignId": 181483024866689,
    "keywordText": "KeywordTwo",
    "matchType": "negativeExact",
    "state": "enabled"
  }
]

getNegativeKeyword

Retrieves a negative keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than getNegativeKeywordEx.

$client->getNegativeKeyword(281218602770639);
{
  "keywordId": 281218602770639,
  "adGroupId": 52169162825843,
  "campaignId": 250040549047739,
  "keywordText": "KeywordOne",
  "matchType": "negativeExact",
  "state": "enabled"
}

createNegativeKeywords

Creates one or more negative keywords. Successfully created keywords will be assigned unique keywordIds.

$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")));
[
  {
    "code": "SUCCESS",
    "keywordId": 61857817062026
  },
  {
    "code": "SUCCESS",
    "keywordId": 147623067066967
  }
]

updateNegativeKeywords

Updates one or more negative keywords. Keywords are identified using their keywordIds.

$client->updateNegativeKeywords(
       array(
           array(
               "keywordId" => 61857817062026,
               "state" => "enabled",
               "bid" => 15.0),
           array(
               "keywordId" => 61857817062026,
               "state" => "enabled",
               "bid" => 20.0)));
[
  {
    "code": "SUCCESS",
    "keywordId": 61857817062026
  },
  {
    "code": "INVALID_ARGUMENT",
    "description": "Entity with id 61857817062026 already specified in this update operation."
  }
]

archiveNegativeKeyword

Sets the negative keyword status to archived. This same operation can be performed via an update to the status, but is included for completeness.

$client->archiveNegativeKeyword(61857817062026);
{
  "code": "SUCCESS",
  "keywordId": 61857817062026
}

listCampaignNegativeKeywords

Retrieves a list of negative campaign keywords satisfying optional criteria.

$client->listCampaignNegativeKeywords(array("matchTypeFilter" => "negativeExact"));
[
  {
    "keywordId": 131747786239884,
    "adGroupId": null,
    "campaignId": 181483024866689,
    "keywordText": "Negative Keyword",
    "matchType": "negativeExact",
    "state": "enabled"
  },
  {
    "keywordId": 197201372210821,
    "adGroupId": null,
    "campaignId": 181483024866689,
    "keywordText": "My Negative Keyword",
    "matchType": "negativeExact",
    "state": "enabled"
  }
]

getCampaignNegativeKeyword

Retrieves a campaign negative keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than getCampaignNegativeKeywordEx.

$client->getCampaignNegativeKeyword(197201372210821);
{
  "keywordId": 197201372210821,
  "adGroupId": null,
  "campaignId": 181483024866689,
  "keywordText": "My Negative Keyword",
  "matchType": "negativeExact",
  "state": "enabled"
}

createCampaignNegativeKeywords

Creates one or more campaign negative keywords. Successfully created keywords will be assigned unique keywordIds.

$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")));
[
  {
    "code": "SUCCESS",
    "keywordId": 196797670902082
  },
  {
    "code": "SUCCESS",
    "keywordId": 186203479904657
  }
]

updateCampaignNegativeKeywords

Updates one or more campaign negative keywords. Keywords are identified using their keywordIds.

Campaign negative keywords can currently only be removed.

removeCampaignNegativeKeyword

Sets the campaign negative keyword status to deleted. This same operation can be performed via an update to the status, but is included for completeness.

$client->removeCampaignNegativeKeyword(186203479904657);
{
  "code": "SUCCESS",
  "keywordId": 186203479904657
}

listProductAds

Retrieves a list of product ads satisfying optional criteria.

$client->listProductAds(array("stateFilter" => "enabled"));
[
  {
    "adId": 247309761200483,
    "adGroupId": 262960563101486,
    "campaignId": 181483024866689,
    "sku": "TEST001",
    "state": "enabled"
  }
]

getProductAd

Retrieves a product ad by Id. Note that this call returns the minimal set of product ad fields, but is more efficient than getProductAdEx.

$client->getProductAd(247309761200483);
{
  "adId": 247309761200483,
  "adGroupId": 262960563101486,
  "campaignId": 181483024866689,
  "sku": "TEST001",
  "state": "enabled"
}

createProductAds

Creates one or more product ads. Successfully created product ads will be assigned unique adIds.

$client->createProductAds(
    array(
        array(
            "campaignId" => 181483024866689,
            "adGroupId" => 262960563101486,
            "sku" => "TEST002",
            "state" => "enabled"),
        array(
            "campaignId" => 181483024866689,
            "adGroupId" => 262960563101486,
            "sku" => "TEST003",
            "state" => "enabled")));
[
  {
    "code": "SUCCESS",
    "adId": 239870616623537
  },
  {
    "code": "SUCCESS",
    "adId": 191456410590622
  }
]

updateProductAds

Updates one or more product ads. Product ads are identified using their adIds.

$client->updateProductAds(
    array(
        array(
            "adId" => 239870616623537,
            "state" => "archived"),
        array(
            "adId" => 191456410590622,
            "state" => "archived")));
[
  {
    "code": "SUCCESS",
    "adId": 239870616623537
  },
  {
    "code": "SUCCESS",
    "adId": 191456410590622
  }
]

archiveProductAd

Sets the product ad status to archived. This same operation can be performed via an update, but is included for completeness.

$client->archiveProductAd(239870616623537);
{
  "code": "SUCCESS",
  "adId": 239870616623537
}

requestSnapshot

Request a snapshot report for all entities of a single type.

$client->requestSnapshot(
    "campaigns",
    array("stateFilter" => "enabled,paused,archived",
          "campaignType" => "sponsoredProducts"));
{
  "snapshotId": "amzn1.clicksAPI.v1.p1.573A0477.ec41773a-1659-4013-8eb9-fa18c87ef5df",
  "recordType": "campaign",
  "status": "IN_PROGRESS"
}

getSnapshot

Retrieve a previously requested report.

$client->getSnapshot("amzn1.clicksAPI.v1.p1.573A0477.ec41773a-1659-4013-8eb9-fa18c87ef5df");
[
  {
    "campaignId": 181483024866689,
    "name": "Campaign One",
    "campaignType": "sponsoredProducts",
    "targetingType": "manual",
    "dailyBudget": 5.0,
    "startDate": "20160330",
    "state": "archived"
  },
  {
    "campaignId": 59836775211065,
    "name": "Campaign Two",
    "campaignType": "sponsoredProducts",
    "targetingType": "manual",
    "dailyBudget": 10.99,
    "startDate": "20160330",
    "state": "archived"
  },
  {
    "campaignId": 254238342004647,
    "name": "Campaign Three",
    "campaignType": "sponsoredProducts",
    "targetingType": "manual",
    "dailyBudget": 99.99,
    "startDate": "20160510",
    "state": "enabled"
  }
]

requestReport

Request a customized performance report for all entities of a single type which have performance data to report.

$client->requestReport(
    "campaigns",
    array("reportDate" => "20160515",
          "campaignType" => "sponsoredProducts",
          "metrics" => "impressions,clicks,cost"));
{
  "reportId": "amzn1.clicksAPI.v1.m1.573A0808.32908def-66a1-4ce2-8f12-780dc4ae1d43",
  "recordType": "campaign",
  "status": "IN_PROGRESS",
  "statusDetails": "Report is submitted"
}

getReport

Retrieve a previously requested report.

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

Sandbox will return dummy data.

[
  {
    "cost": 647.75,
    "campaignId": 230751293360275,
    "clicks": 2591,
    "impressions": 58288
  },
  {
    "cost": 619.5,
    "campaignId": 52110033002744,
    "clicks": 2478,
    "impressions": 68408
  },
  {
    "cost": 151.91,
    "campaignId": 140739567440917,
    "clicks": 633,
    "impressions": 17343
  },
  {
    "cost": 143.46,
    "campaignId": 79132327246328,
    "clicks": 797,
    "impressions": 48903
  }
]

getAdGroupBidRecommendations

Request bid recommendations for specified ad group.

$client->getAdGroupBidRecommendations(1234509876);
{
  "adGroupId": 1234509876,
  "suggestedBid": {
    "rangeEnd": 2.16,
    "rangeStart": 0.67,
    "suggested": 1.67
  }
}

getKeywordBidRecommendations

Request bid recommendations for specified keyword.

$client->getKeywordBidRecommendations(85243141758914);
{
  "keywordId": 85243141758914,
  "adGroupId": 252673310548066,
  "suggestedBid": {
    "rangeEnd": 3.18,
    "rangeStart": 0.35,
    "suggested": 2.97
  }
}

bulkGetKeywordBidRecommendations

Request bid recommendations for a list of up to 100 keywords.

$client->bulkGetKeywordBidRecommendations(
    242783265349805,
    array(
        array("keyword" => "testKeywordOne",
              "matchType" => "exact"),
        array("keyword" => "testKeywordTwo",
              "matchType" => "exact")
    ));
{
  "adGroupId": 242783265349805,
  "recommendations": [
    {
      "code": "SUCCESS",
      "keyword": "testKeywordOne",
      "matchType": "exact",
      "suggestedBid": {
        "rangeEnd": 2.67,
        "rangeStart": 0.38,
        "suggested": 2.07
      }
    },
    {
      "code": "SUCCESS",
      "keyword": "testKeywordTwo",
      "matchType": "exact",
      "suggestedBid": {
        "rangeEnd": 3.19,
        "rangeStart": 0.79,
        "suggested": 3.03
      }
    }
  ]
}

getAdGroupKeywordSuggestions

Request keyword suggestions for specified ad group.

$client->getAdGroupKeywordSuggestions(
    array("adGroupId" => 1234567890,
          "maxNumSuggestions" => 2,
          "adStateFilter" => "enabled"));
{
  "adGroupId": 1234567890,
  "suggestedKeywords": [
    {
      "keywordText": "keyword PRODUCT_AD_A 1",
      "matchType": "broad"
    },
    {
      "keywordText": "keyword PRODUCT_AD_B 1",
      "matchType": "broad"
    }
  ]
}

getAdGroupKeywordSuggestionsEx

Request keyword suggestions for specified ad group, extended version. Adds the ability to return bid recommendation for returned keywords.

$client->getAdGroupKeywordSuggestionsEx(
    array("adGroupId" => 1234567890,
          "maxNumSuggestions" => 2,
          "suggestBids" => "yes",
          "adStateFilter" => "enabled"));
[
  {
    "adGroupId": 1234567890,
    "campaignId": 0987654321,
    "keywordText": "keyword TESTASINXX 1",
    "matchType": "broad",
    "state": "enabled",
    "bid": 1.84
  },
  {
    "adGroupId": 1234567890,
    "campaignId": 0987654321,
    "keywordText": "keyword TESTASINXX 2",
    "matchType": "broad",
    "state": "enabled",
    "bid": 1.07
  }
]

getAsinKeywordSuggestions

Request keyword suggestions for specified asin.

$client->getAsinKeywordSuggestions(
    array("asin" => "B00IJSNPM0",
          "maxNumSuggestions" => 2));
[
  {
    "keywordText": "keyword B00IJSNPM0 1",
    "matchType": "broad"
  },
  {
    "keywordText": "keyword B00IJSNPM0 2",
    "matchType": "broad"
  }
]

bulkGetAsinKeywordSuggestions

Request keyword suggestions for a list of asin.

$client->bulkGetAsinKeywordSuggestions(
    array("asins" => array(
              "B00IJSNPM0",
              "B00IJSO1NM"),
          "maxNumSuggestions" => 2));
[
  {
    "keywordText": "keyword B00IJSNPM0 1",
    "matchType": "broad"
  },
  {
    "keywordText": "keyword B00IJSO1NM 1",
    "matchType": "broad"
  }
]