├── AmazonAdvertisingApi
├── Versions.php
├── Regions.php
├── CurlRequest.php
└── Client.php
├── tests
├── phpunit.xml
└── ClientTest.php
├── NOTICE
├── composer.json
├── LICENSE
└── README.md
/AmazonAdvertisingApi/Versions.php:
--------------------------------------------------------------------------------
1 | "v1",
8 | "applicationVersion" => "1.2"
9 | );
10 | }
11 |
--------------------------------------------------------------------------------
/tests/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 | .
12 |
13 |
14 |
15 |
16 |
17 | .
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"). You may not use
4 | this file except in compliance with the License. A copy of the License is
5 | located at http://aws.amazon.com/apache2.0/ or in the "license" file
6 | accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT
7 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
8 | License for the specific language governing permissions and limitations under
9 | the License.
10 |
--------------------------------------------------------------------------------
/AmazonAdvertisingApi/Regions.php:
--------------------------------------------------------------------------------
1 | array(
8 | "prod" => "advertising-api.amazon.com",
9 | "sandbox" => "advertising-api-test.amazon.com",
10 | "tokenUrl" => "api.amazon.com/auth/o2/token"),
11 | "eu" => array(
12 | "prod" => "advertising-api-eu.amazon.com",
13 | "sandbox" => "advertising-api-test.amazon.com",
14 | "tokenUrl" => "api.amazon.com/auth/o2/token"
15 | )
16 | );
17 | }
18 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "amzn/amazon-advertising-api-php-sdk",
3 | "type": "library",
4 | "description": "Amazon Advertising API Client Library",
5 | "keywords": [
6 | "amazon",
7 | "advertising",
8 | "client",
9 | "library",
10 | "php",
11 | "sdk"
12 | ],
13 | "homepage": "https://advertising.amazon.com/",
14 | "license": "Apache OSL-2",
15 | "authors": [
16 | {
17 | "name": "SSPA AIR Dev",
18 | "email": "nobody@amazon.com"
19 | }
20 | ],
21 | "autoload": {
22 | "psr-4": {
23 | "AmazonAdvertisingApi\\": "AmazonAdvertisingApi/"
24 | }
25 | },
26 | "require": {
27 | "ext-curl": "*",
28 | "php": ">=5.3.0"
29 | },
30 | "repositories": [
31 | {
32 | "type": "vcs",
33 | "url": "https://github.com/amzn/amazon-advertising-api-php-sdk"
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/AmazonAdvertisingApi/CurlRequest.php:
--------------------------------------------------------------------------------
1 | reset();
12 | }
13 |
14 | public function reset()
15 | {
16 | $this->handle = curl_init();
17 | curl_setopt($this->handle, CURLOPT_PORT, 443);
18 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, true);
19 | curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 2);
20 | curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
21 | curl_setopt($this->handle, CURLOPT_HEADER, false);
22 | if (defined("CURLOPT_IPRESOLVE")) {
23 | curl_setopt($this->handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 | }
25 | curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array($this, "_handleHeaderLine"));
26 | }
27 |
28 | public function setOption($name, $value)
29 | {
30 | curl_setopt($this->handle, $name, $value);
31 | }
32 |
33 | public function execute()
34 | {
35 | return curl_exec($this->handle);
36 | }
37 |
38 | public function getInfo()
39 | {
40 | return curl_getinfo($this->handle);
41 | }
42 |
43 | public function getError()
44 | {
45 | return curl_error($this->handle);
46 | }
47 |
48 | public function close()
49 | {
50 | curl_close($this->handle);
51 | }
52 |
53 | private function _handleHeaderLine($ch, $line)
54 | {
55 | $matches = array();
56 | if (preg_match("/x-amz-request-id:\ \S+/", $line)) {
57 | preg_match_all("/[^\ ]\S+/", $line, $matches);
58 | if (count($matches) > 0) {
59 | if (count($matches[0]) > 1) {
60 | $this->requestId = $matches[0][1];
61 | }
62 | }
63 | }
64 | return strlen($line);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/tests/ClientTest.php:
--------------------------------------------------------------------------------
1 | "amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
12 | "clientSecret" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
13 | "region" => "na",
14 | "accessToken" => "Atza%7Ctest",
15 | "refreshToken" => "Atzr%7Ctest",
16 | "sandbox" => true);
17 |
18 |
19 | public function setUp()
20 | {
21 | $this->return_value = array(
22 | "code" => "200",
23 | "success" => true,
24 | "requestId" => "test",
25 | "response" => "SUCCESS");
26 |
27 | $this->client = $this->getMockBuilder("AmazonAdvertisingApi\Client")
28 | ->setConstructorArgs(array($this->config))
29 | ->setMethods(array("_executeRequest"))
30 | ->getMock();
31 |
32 | $this->client->expects($this->any())
33 | ->method("_executeRequest")
34 | ->will($this->returnValue($this->return_value));
35 | }
36 |
37 |
38 | public function testValidateClientId()
39 | {
40 | $testConfig = $this->config;
41 | $testConfig["clientId"] = "bad";
42 | try {
43 | $client = new Client($testConfig);
44 | } catch (\Exception $expected) {
45 | $this->assertRegExp("/Invalid parameter value for clientId./", strval($expected));
46 | }
47 | }
48 |
49 | public function testValidateClientSecret()
50 | {
51 | $testConfig = $this->config;
52 | $testConfig["clientSecret"] = "bad";
53 | try {
54 | $client = new Client($testConfig);
55 | } catch (\Exception $expected) {
56 | $this->assertRegExp("/Invalid parameter value for clientSecret./", strval($expected));
57 | }
58 | }
59 |
60 | public function testValidateRegion()
61 | {
62 | $testConfig = $this->config;
63 | $testConfig["region"] = "bad";
64 | try {
65 | $client = new Client($testConfig);
66 | } catch (\Exception $expected) {
67 | $this->assertRegExp("/Invalid region./", strval($expected));
68 | }
69 | }
70 |
71 | public function testValidateAccessToken()
72 | {
73 | $testConfig = $this->config;
74 | $testConfig["accessToken"] = "bad";
75 | try {
76 | $client = new Client($testConfig);
77 | } catch (\Exception $expected) {
78 | $this->assertRegExp("/Invalid parameter value for accessToken./", strval($expected));
79 | }
80 | }
81 |
82 | public function testValidateRefreshToken()
83 | {
84 | $testConfig = $this->config;
85 | $testConfig["refreshToken"] = "bad";
86 | try {
87 | $client = new Client($testConfig);
88 | } catch (\Exception $expected) {
89 | $this->assertRegExp("/Invalid parameter value for refreshToken./", strval($expected));
90 | }
91 | }
92 |
93 | public function testValidateSandbox()
94 | {
95 | $testConfig = $this->config;
96 | $testConfig["sandbox"] = "bad";
97 | try {
98 | $client = new Client($testConfig);
99 | } catch (\Exception $expected) {
100 | $this->assertRegExp("/Invalid parameter value for sandbox./", strval($expected));
101 | }
102 | }
103 |
104 | public function testListProfiles()
105 | {
106 | $request = $this->client->listProfiles();
107 | $this->assertEquals($this->return_value, $request);
108 | }
109 |
110 | public function testGetProfile()
111 | {
112 | $request = $this->client->getProfile("test");
113 | $this->assertEquals($this->return_value, $request);
114 | }
115 |
116 | public function testUpdateProfiles()
117 | {
118 | $request = $this->client->updateProfiles("test");
119 | $this->assertEquals($this->return_value, $request);
120 | }
121 |
122 | public function testGetCampaign()
123 | {
124 | $request = $this->client->getCampaign("test");
125 | $this->assertEquals($this->return_value, $request);
126 | }
127 |
128 | public function testGetCampaignEx()
129 | {
130 | $request = $this->client->getCampaignEx("test");
131 | $this->assertEquals($this->return_value, $request);
132 | }
133 |
134 | public function testCreateCampaigns()
135 | {
136 | $request = $this->client->createCampaigns("test");
137 | $this->assertEquals($this->return_value, $request);
138 | }
139 |
140 | public function testArchiveCampaign()
141 | {
142 | $request = $this->client->archiveCampaign("test");
143 | $this->assertEquals($this->return_value, $request);
144 | }
145 |
146 | public function testListCampaigns()
147 | {
148 | $request = $this->client->listCampaigns();
149 | $this->assertEquals($this->return_value, $request);
150 | }
151 |
152 | public function testListCampaignsEx()
153 | {
154 | $request = $this->client->listCampaignsEx();
155 | $this->assertEquals($this->return_value, $request);
156 | }
157 |
158 | public function testGetAdGroup()
159 | {
160 | $request = $this->client->getAdGroup("test");
161 | $this->assertEquals($this->return_value, $request);
162 | }
163 |
164 | public function testGetAdGroupEx()
165 | {
166 | $request = $this->client->getAdGroupEx("test");
167 | $this->assertEquals($this->return_value, $request);
168 | }
169 |
170 | public function testCreateAdGroups()
171 | {
172 | $request = $this->client->createAdGroups("test");
173 | $this->assertEquals($this->return_value, $request);
174 | }
175 |
176 | public function testUpdateAdGroups()
177 | {
178 | $request = $this->client->updateAdGroups("test");
179 | $this->assertEquals($this->return_value, $request);
180 | }
181 |
182 | public function testArchiveAdGroup()
183 | {
184 | $request = $this->client->archiveAdGroup("test");
185 | $this->assertEquals($this->return_value, $request);
186 | }
187 |
188 | public function testListAdGroups()
189 | {
190 | $request = $this->client->listAdGroups();
191 | $this->assertEquals($this->return_value, $request);
192 | }
193 |
194 | public function testListAdGroupsEx()
195 | {
196 | $request = $this->client->listAdGroupsEx();
197 | $this->assertEquals($this->return_value, $request);
198 | }
199 |
200 | public function testGetBiddableKeyword()
201 | {
202 | $request = $this->client->getBiddableKeyword("test");
203 | $this->assertEquals($this->return_value, $request);
204 | }
205 |
206 | public function testGetBiddableKeywordEx()
207 | {
208 | $request = $this->client->getBiddableKeywordEx("test");
209 | $this->assertEquals($this->return_value, $request);
210 | }
211 |
212 | public function testCreateBiddableKeywords()
213 | {
214 | $request = $this->client->createBiddableKeywords("test");
215 | $this->assertEquals($this->return_value, $request);
216 | }
217 |
218 | public function updateCreateBiddableKeywords()
219 | {
220 | $request = $this->client->updateBiddableKeywords("test");
221 | $this->assertEquals($this->return_value, $request);
222 | }
223 |
224 | public function testArchiveBiddableKeyword()
225 | {
226 | $request = $this->client->archiveBiddableKeyword("test");
227 | $this->assertEquals($this->return_value, $request);
228 | }
229 |
230 | public function testListBiddableKeywords()
231 | {
232 | $request = $this->client->listBiddableKeywords();
233 | $this->assertEquals($this->return_value, $request);
234 | }
235 |
236 | public function testListBiddableKeywordsEx()
237 | {
238 | $request = $this->client->listBiddableKeywordsEx();
239 | $this->assertEquals($this->return_value, $request);
240 | }
241 |
242 | public function testGetNegativeKeyword()
243 | {
244 | $request = $this->client->getNegativeKeyword("test");
245 | $this->assertEquals($this->return_value, $request);
246 | }
247 |
248 | public function testGetNegativeKeywordEx()
249 | {
250 | $request = $this->client->getNegativeKeywordEx("test");
251 | $this->assertEquals($this->return_value, $request);
252 | }
253 |
254 | public function testCreateNegativeKeywords()
255 | {
256 | $request = $this->client->createNegativeKeywords("test");
257 | $this->assertEquals($this->return_value, $request);
258 | }
259 |
260 | public function testUpdateNegativeKeywords()
261 | {
262 | $request = $this->client->updateNegativeKeywords("test");
263 | $this->assertEquals($this->return_value, $request);
264 | }
265 |
266 | public function testArchiveNegativeKeyword()
267 | {
268 | $request = $this->client->archiveNegativeKeyword("test");
269 | $this->assertEquals($this->return_value, $request);
270 | }
271 |
272 | public function testListNegativeKeywords()
273 | {
274 | $request = $this->client->listNegativeKeywords();
275 | $this->assertEquals($this->return_value, $request);
276 | }
277 |
278 | public function testListNegativeKeywordsEx()
279 | {
280 | $request = $this->client->listNegativeKeywordsEx();
281 | $this->assertEquals($this->return_value, $request);
282 | }
283 |
284 | public function testGetCampaignNegativeKeyword()
285 | {
286 | $request = $this->client->getCampaignNegativeKeyword("test");
287 | $this->assertEquals($this->return_value, $request);
288 | }
289 |
290 | public function testGetCampaignNegativeKeywordEx()
291 | {
292 | $request = $this->client->getCampaignNegativeKeywordEx("test");
293 | $this->assertEquals($this->return_value, $request);
294 | }
295 |
296 | public function testCreateCampaignNegativeKeywords()
297 | {
298 | $request = $this->client->createCampaignNegativeKeywords("test");
299 | $this->assertEquals($this->return_value, $request);
300 | }
301 |
302 | public function testUpdateCampaignNegativeKeywords()
303 | {
304 | $request = $this->client->updateCampaignNegativeKeywords("test");
305 | $this->assertEquals($this->return_value, $request);
306 | }
307 |
308 | public function testRemoveCampaignNegativeKeyword()
309 | {
310 | $request = $this->client->removeCampaignNegativeKeyword("test");
311 | $this->assertEquals($this->return_value, $request);
312 | }
313 |
314 | public function testListCampaignNegativeKeywords()
315 | {
316 | $request = $this->client->listCampaignNegativeKeywords();
317 | $this->assertEquals($this->return_value, $request);
318 | }
319 |
320 | public function testListCampaignNegativeKeywordsEx()
321 | {
322 | $request = $this->client->listCampaignNegativeKeywordsEx();
323 | $this->assertEquals($this->return_value, $request);
324 | }
325 |
326 | public function testGetProductAd()
327 | {
328 | $request = $this->client->getProductAd("test");
329 | $this->assertEquals($this->return_value, $request);
330 | }
331 |
332 | public function testGetProductAdEx()
333 | {
334 | $request = $this->client->getProductAdEx("test");
335 | $this->assertEquals($this->return_value, $request);
336 | }
337 |
338 | public function testCreateProductAds()
339 | {
340 | $request = $this->client->createProductAds("test");
341 | $this->assertEquals($this->return_value, $request);
342 | }
343 |
344 | public function testUpdateProductAds()
345 | {
346 | $request = $this->client->updateProductAds("test");
347 | $this->assertEquals($this->return_value, $request);
348 | }
349 |
350 | public function testArchiveProductAd()
351 | {
352 | $request = $this->client->archiveProductAd("test");
353 | $this->assertEquals($this->return_value, $request);
354 | }
355 |
356 | public function testListProductAds()
357 | {
358 | $request = $this->client->listProductAds();
359 | $this->assertEquals($this->return_value, $request);
360 | }
361 |
362 | public function testListProductAdsEx()
363 | {
364 | $request = $this->client->listProductAdsEx();
365 | $this->assertEquals($this->return_value, $request);
366 | }
367 |
368 | public function testGetAdGroupBidRecommendations()
369 | {
370 | $request = $this->client->getAdGroupBidRecommendations("test");
371 | $this->assertEquals($this->return_value, $request);
372 | }
373 |
374 | public function testGetKeywordBidRecommendations()
375 | {
376 | $request = $this->client->getKeywordBidRecommendations("test");
377 | $this->assertEquals($this->return_value, $request);
378 | }
379 |
380 | public function testBulkGetKeywordBidRecommendations()
381 | {
382 | $request = $this->client->getKeywordBidRecommendations("test");
383 | $this->assertEquals($this->return_value, $request);
384 | }
385 |
386 | public function testGetAdGroupKeywordSuggestions()
387 | {
388 | $request = $this->client->getAdGroupKeywordSuggestions(
389 | array("adGroupId" => 12345));
390 | $this->assertEquals($this->return_value, $request);
391 | }
392 |
393 | public function testGetAdGroupKeywordSuggestionsEx()
394 | {
395 | $request = $this->client->getAdGroupKeywordSuggestionsEx(
396 | array("adGroupId" => 12345));
397 | $this->assertEquals($this->return_value, $request);
398 | }
399 |
400 | public function testGetAsinKeywordSuggestions()
401 | {
402 | $request = $this->client->getAsinKeywordSuggestions(
403 | array("asin" => 12345));
404 | $this->assertEquals($this->return_value, $request);
405 | }
406 |
407 | public function testBulkGetAsinKeywordSuggestions()
408 | {
409 | $request = $this->client->bulkGetAsinKeywordSuggestions(
410 | array("asins" => array("ASIN1", "ASIN2")));
411 | $this->assertEquals($this->return_value, $request);
412 | }
413 |
414 | public function testRequestSnapshot()
415 | {
416 | $request = $this->client->requestSnapshot("test");
417 | $this->assertEquals($this->return_value, $request);
418 | }
419 |
420 | public function testGetSnapshot()
421 | {
422 | $request = $this->client->getSnapshot("test");
423 | $this->assertEquals($this->return_value, $request);
424 | }
425 |
426 | public function testRequestReport()
427 | {
428 | $request = $this->client->requestReport("test");
429 | $this->assertEquals($this->return_value, $request);
430 | }
431 |
432 | public function testGetReport()
433 | {
434 | $request = $this->client->getReport("test");
435 | $this->assertEquals($this->return_value, $request);
436 | }
437 | }
438 |
--------------------------------------------------------------------------------
/AmazonAdvertisingApi/Client.php:
--------------------------------------------------------------------------------
1 | null,
12 | "clientSecret" => null,
13 | "region" => null,
14 | "accessToken" => null,
15 | "refreshToken" => null,
16 | "sandbox" => false);
17 |
18 | private $apiVersion = null;
19 | private $applicationVersion = null;
20 | private $userAgent = null;
21 | private $endpoint = null;
22 | private $tokenUrl = null;
23 | private $requestId = null;
24 | private $endpoints = null;
25 | private $versionStrings = null;
26 |
27 | public $profileId = null;
28 |
29 | public function __construct($config)
30 | {
31 | $regions = new Regions();
32 | $this->endpoints = $regions->endpoints;
33 |
34 | $versions = new Versions();
35 | $this->versionStrings = $versions->versionStrings;
36 |
37 | $this->apiVersion = $this->versionStrings["apiVersion"];
38 | $this->applicationVersion = $this->versionStrings["applicationVersion"];
39 | $this->userAgent = "AdvertisingAPI PHP Client Library v{$this->applicationVersion}";
40 |
41 | $this->_validateConfig($config);
42 | $this->_validateConfigParameters();
43 | $this->_setEndpoints();
44 |
45 | if (is_null($this->config["accessToken"]) && !is_null($this->config["refreshToken"])) {
46 | /* convenience */
47 | $this->doRefreshToken();
48 | }
49 | }
50 |
51 | public function doRefreshToken()
52 | {
53 | $headers = array(
54 | "Content-Type: application/x-www-form-urlencoded;charset=UTF-8",
55 | "User-Agent: {$this->userAgent}"
56 | );
57 |
58 | $refresh_token = rawurldecode($this->config["refreshToken"]);
59 |
60 | $params = array(
61 | "grant_type" => "refresh_token",
62 | "refresh_token" => $refresh_token,
63 | "client_id" => $this->config["clientId"],
64 | "client_secret" => $this->config["clientSecret"]);
65 |
66 | $data = "";
67 | foreach ($params as $k => $v) {
68 | $data .= "{$k}=".rawurlencode($v)."&";
69 | }
70 |
71 | $url = "https://{$this->tokenUrl}";
72 |
73 | $request = new CurlRequest();
74 | $request->setOption(CURLOPT_URL, $url);
75 | $request->setOption(CURLOPT_HTTPHEADER, $headers);
76 | $request->setOption(CURLOPT_USERAGENT, $this->userAgent);
77 | $request->setOption(CURLOPT_POST, true);
78 | $request->setOption(CURLOPT_POSTFIELDS, rtrim($data, "&"));
79 |
80 | $response = $this->_executeRequest($request);
81 |
82 | $response_array = json_decode($response["response"], true);
83 | if (array_key_exists("access_token", $response_array)) {
84 | $this->config["accessToken"] = $response_array["access_token"];
85 | } else {
86 | $this->_logAndThrow("Unable to refresh token. 'access_token' not found in response. ". print_r($response, true));
87 | }
88 |
89 | return $response;
90 | }
91 |
92 | public function listProfiles()
93 | {
94 | return $this->_operation("profiles");
95 | }
96 |
97 | public function registerProfile($data)
98 | {
99 | return $this->_operation("profiles/register", $data, "PUT");
100 | }
101 |
102 | public function registerProfileStatus($profileId)
103 | {
104 | return $this->_operation("profiles/register/{$profileId}/status");
105 | }
106 |
107 | public function getProfile($profileId)
108 | {
109 | return $this->_operation("profiles/{$profileId}");
110 | }
111 |
112 | public function updateProfiles($data)
113 | {
114 | return $this->_operation("profiles", $data, "PUT");
115 | }
116 |
117 | public function getCampaign($campaignId)
118 | {
119 | return $this->_operation("campaigns/{$campaignId}");
120 | }
121 |
122 | public function getCampaignEx($campaignId)
123 | {
124 | return $this->_operation("campaigns/extended/{$campaignId}");
125 | }
126 |
127 | public function createCampaigns($data)
128 | {
129 | return $this->_operation("campaigns", $data, "POST");
130 | }
131 |
132 | public function updateCampaigns($data)
133 | {
134 | return $this->_operation("campaigns", $data, "PUT");
135 | }
136 |
137 | public function archiveCampaign($campaignId)
138 | {
139 | return $this->_operation("campaigns/{$campaignId}", null, "DELETE");
140 | }
141 |
142 | public function listCampaigns($data = null)
143 | {
144 | return $this->_operation("campaigns", $data);
145 | }
146 |
147 | public function listCampaignsEx($data = null)
148 | {
149 | return $this->_operation("campaigns/extended", $data);
150 | }
151 |
152 | public function getAdGroup($adGroupId)
153 | {
154 | return $this->_operation("adGroups/{$adGroupId}");
155 | }
156 |
157 | public function getAdGroupEx($adGroupId)
158 | {
159 | return $this->_operation("adGroups/extended/{$adGroupId}");
160 | }
161 |
162 | public function createAdGroups($data)
163 | {
164 | return $this->_operation("adGroups", $data, "POST");
165 | }
166 |
167 | public function updateAdGroups($data)
168 | {
169 | return $this->_operation("adGroups", $data, "PUT");
170 | }
171 |
172 | public function archiveAdGroup($adGroupId)
173 | {
174 | return $this->_operation("adGroups/{$adGroupId}", null, "DELETE");
175 | }
176 |
177 | public function listAdGroups($data = null)
178 | {
179 | return $this->_operation("adGroups", $data);
180 | }
181 |
182 | public function listAdGroupsEx($data = null)
183 | {
184 | return $this->_operation("adGroups/extended", $data);
185 | }
186 |
187 | public function getBiddableKeyword($keywordId)
188 | {
189 | return $this->_operation("keywords/{$keywordId}");
190 | }
191 |
192 | public function getBiddableKeywordEx($keywordId)
193 | {
194 | return $this->_operation("keywords/extended/{$keywordId}");
195 | }
196 |
197 | public function createBiddableKeywords($data)
198 | {
199 | return $this->_operation("keywords", $data, "POST");
200 | }
201 |
202 | public function updateBiddableKeywords($data)
203 | {
204 | return $this->_operation("keywords", $data, "PUT");
205 | }
206 |
207 | public function archiveBiddableKeyword($keywordId)
208 | {
209 | return $this->_operation("keywords/{$keywordId}", null, "DELETE");
210 | }
211 |
212 | public function listBiddableKeywords($data = null)
213 | {
214 | return $this->_operation("keywords", $data);
215 | }
216 |
217 | public function listBiddableKeywordsEx($data = null)
218 | {
219 | return $this->_operation("keywords/extended", $data);
220 | }
221 |
222 | public function getNegativeKeyword($keywordId)
223 | {
224 | return $this->_operation("negativeKeywords/{$keywordId}");
225 | }
226 |
227 | public function getNegativeKeywordEx($keywordId)
228 | {
229 | return $this->_operation("negativeKeywords/extended/{$keywordId}");
230 | }
231 |
232 | public function createNegativeKeywords($data)
233 | {
234 | return $this->_operation("negativeKeywords", $data, "POST");
235 | }
236 |
237 | public function updateNegativeKeywords($data)
238 | {
239 | return $this->_operation("negativeKeywords", $data, "PUT");
240 | }
241 |
242 | public function archiveNegativeKeyword($keywordId)
243 | {
244 | return $this->_operation("negativeKeywords/{$keywordId}", null, "DELETE");
245 | }
246 |
247 | public function listNegativeKeywords($data = null)
248 | {
249 | return $this->_operation("negativeKeywords", $data);
250 | }
251 |
252 | public function listNegativeKeywordsEx($data = null)
253 | {
254 | return $this->_operation("negativeKeywords/extended", $data);
255 | }
256 |
257 | public function getCampaignNegativeKeyword($keywordId)
258 | {
259 | return $this->_operation("campaignNegativeKeywords/{$keywordId}");
260 | }
261 |
262 | public function getCampaignNegativeKeywordEx($keywordId)
263 | {
264 | return $this->_operation("campaignNegativeKeywords/extended/{$keywordId}");
265 | }
266 |
267 | public function createCampaignNegativeKeywords($data)
268 | {
269 | return $this->_operation("campaignNegativeKeywords", $data, "POST");
270 | }
271 |
272 | public function updateCampaignNegativeKeywords($data)
273 | {
274 | return $this->_operation("campaignNegativeKeywords", $data, "PUT");
275 | }
276 |
277 | public function removeCampaignNegativeKeyword($keywordId)
278 | {
279 | return $this->_operation("campaignNegativeKeywords/{$keywordId}", null, "DELETE");
280 | }
281 |
282 | public function listCampaignNegativeKeywords($data = null)
283 | {
284 | return $this->_operation("campaignNegativeKeywords", $data);
285 | }
286 |
287 | public function listCampaignNegativeKeywordsEx($data = null)
288 | {
289 | return $this->_operation("campaignNegativeKeywords/extended", $data);
290 | }
291 |
292 | public function getProductAd($productAdId)
293 | {
294 | return $this->_operation("productAds/{$productAdId}");
295 | }
296 |
297 | public function getProductAdEx($productAdId)
298 | {
299 | return $this->_operation("productAds/extended/{$productAdId}");
300 | }
301 |
302 | public function createProductAds($data)
303 | {
304 | return $this->_operation("productAds", $data, "POST");
305 | }
306 |
307 | public function updateProductAds($data)
308 | {
309 | return $this->_operation("productAds", $data, "PUT");
310 | }
311 |
312 | public function archiveProductAd($productAdId)
313 | {
314 | return $this->_operation("productAds/{$productAdId}", null, "DELETE");
315 | }
316 |
317 | public function listProductAds($data = null)
318 | {
319 | return $this->_operation("productAds", $data);
320 | }
321 |
322 | public function listProductAdsEx($data = null)
323 | {
324 | return $this->_operation("productAds/extended", $data);
325 | }
326 |
327 | public function getAdGroupBidRecommendations($adGroupId)
328 | {
329 | return $this->_operation("adGroups/{$adGroupId}/bidRecommendations");
330 | }
331 |
332 | public function getKeywordBidRecommendations($keywordId)
333 | {
334 | return $this->_operation("keywords/{$keywordId}/bidRecommendations");
335 | }
336 |
337 | public function bulkGetKeywordBidRecommendations($adGroupId, $data)
338 | {
339 | $data = array(
340 | "adGroupId" => $adGroupId,
341 | "keywords" => $data);
342 | return $this->_operation("keywords/bidRecommendations", $data, "POST");
343 | }
344 |
345 | public function getAdGroupKeywordSuggestions($data)
346 | {
347 | $adGroupId = $data["adGroupId"];
348 | unset($data["adGroupId"]);
349 | return $this->_operation("adGroups/{$adGroupId}/suggested/keywords", $data);
350 | }
351 |
352 | public function getAdGroupKeywordSuggestionsEx($data)
353 | {
354 | $adGroupId = $data["adGroupId"];
355 | unset($data["adGroupId"]);
356 | return $this->_operation("adGroups/{$adGroupId}/suggested/keywords/extended", $data);
357 | }
358 |
359 | public function getAsinKeywordSuggestions($data)
360 | {
361 | $asin = $data["asin"];
362 | unset($data["asin"]);
363 | return $this->_operation("asins/{$asin}/suggested/keywords", $data);
364 | }
365 |
366 | public function bulkGetAsinKeywordSuggestions($data)
367 | {
368 | return $this->_operation("asins/suggested/keywords", $data, "POST");
369 | }
370 |
371 | public function requestSnapshot($recordType, $data = null)
372 | {
373 | return $this->_operation("{$recordType}/snapshot", $data, "POST");
374 | }
375 |
376 | public function getSnapshot($snapshotId)
377 | {
378 | $req = $this->_operation("snapshots/{$snapshotId}");
379 | if ($req["success"]) {
380 | $json = json_decode($req["response"], true);
381 | if ($json["status"] == "SUCCESS") {
382 | return $this->_download($json["location"]);
383 | }
384 | }
385 | return $req;
386 | }
387 |
388 | public function requestReport($recordType, $data = null)
389 | {
390 | return $this->_operation("{$recordType}/report", $data, "POST");
391 | }
392 |
393 | public function getReport($reportId)
394 | {
395 | $req = $this->_operation("reports/{$reportId}");
396 | if ($req["success"]) {
397 | $json = json_decode($req["response"], true);
398 | if ($json["status"] == "SUCCESS") {
399 | return $this->_download($json["location"]);
400 | }
401 | }
402 | return $req;
403 | }
404 |
405 | private function _download($location, $gunzip = false)
406 | {
407 | $headers = array();
408 |
409 | if (!$gunzip) {
410 | /* only send authorization header when not downloading actual file */
411 | array_push($headers, "Authorization: bearer {$this->config["accessToken"]}");
412 | }
413 |
414 | if (!is_null($this->profileId)) {
415 | array_push($headers, "Amazon-Advertising-API-Scope: {$this->profileId}");
416 | }
417 |
418 | $request = new CurlRequest();
419 | $request->setOption(CURLOPT_URL, $location);
420 | $request->setOption(CURLOPT_HTTPHEADER, $headers);
421 | $request->setOption(CURLOPT_USERAGENT, $this->userAgent);
422 |
423 | if ($gunzip) {
424 | $response = $this->_executeRequest($request);
425 | $response["response"] = gzdecode($response["response"]);
426 | return $response;
427 | }
428 |
429 | return $this->_executeRequest($request);
430 | }
431 |
432 | private function _operation($interface, $params = array(), $method = "GET")
433 | {
434 | $headers = array(
435 | "Authorization: bearer {$this->config["accessToken"]}",
436 | "Content-Type: application/json",
437 | "User-Agent: {$this->userAgent}"
438 | );
439 |
440 | if (!is_null($this->profileId)) {
441 | array_push($headers, "Amazon-Advertising-API-Scope: {$this->profileId}");
442 | }
443 |
444 | $request = new CurlRequest();
445 | $url = "{$this->endpoint}/{$interface}";
446 | $this->requestId = null;
447 | $data = "";
448 |
449 | switch (strtolower($method)) {
450 | case "get":
451 | if (!empty($params)) {
452 | $url .= "?";
453 | foreach ($params as $k => $v) {
454 | $url .= "{$k}=".rawurlencode($v)."&";
455 | }
456 | $url = rtrim($url, "&");
457 | }
458 | break;
459 | case "put":
460 | case "post":
461 | case "delete":
462 | if (!empty($params)) {
463 | $data = json_encode($params);
464 | $request->setOption(CURLOPT_POST, true);
465 | $request->setOption(CURLOPT_POSTFIELDS, $data);
466 | }
467 | break;
468 | default:
469 | $this->_logAndThrow("Unknown verb {$method}.");
470 | }
471 |
472 | $request->setOption(CURLOPT_URL, $url);
473 | $request->setOption(CURLOPT_HTTPHEADER, $headers);
474 | $request->setOption(CURLOPT_USERAGENT, $this->userAgent);
475 | $request->setOption(CURLOPT_CUSTOMREQUEST, strtoupper($method));
476 | return $this->_executeRequest($request);
477 | }
478 |
479 | protected function _executeRequest($request)
480 | {
481 | $response = $request->execute();
482 | $this->requestId = $request->requestId;
483 | $response_info = $request->getInfo();
484 | $request->close();
485 |
486 | if ($response_info["http_code"] == 307) {
487 | /* application/octet-stream */
488 | return $this->_download($response_info["redirect_url"], true);
489 | }
490 |
491 | if (!preg_match("/^(2|3)\d{2}$/", $response_info["http_code"])) {
492 | $requestId = 0;
493 | $json = json_decode($response, true);
494 | if (!is_null($json)) {
495 | if (array_key_exists("requestId", $json)) {
496 | $requestId = json_decode($response, true)["requestId"];
497 | }
498 | }
499 | return array("success" => false,
500 | "code" => $response_info["http_code"],
501 | "response" => $response,
502 | "requestId" => $requestId);
503 | } else {
504 | return array("success" => true,
505 | "code" => $response_info["http_code"],
506 | "response" => $response,
507 | "requestId" => $this->requestId);
508 | }
509 | }
510 |
511 | private function _validateConfig($config)
512 | {
513 | if (is_null($config)) {
514 | $this->_logAndThrow("'config' cannot be null.");
515 | }
516 |
517 | foreach ($config as $k => $v) {
518 | if (array_key_exists($k, $this->config)) {
519 | $this->config[$k] = $v;
520 | } else {
521 | $this->_logAndThrow("Unknown parameter '{$k}' in config.");
522 | }
523 | }
524 | return true;
525 | }
526 |
527 | private function _validateConfigParameters()
528 | {
529 | foreach ($this->config as $k => $v) {
530 | if (is_null($v) && $k !== "accessToken" && $k !== "refreshToken") {
531 | $this->_logAndThrow("Missing required parameter '{$k}'.");
532 | }
533 | switch ($k) {
534 | case "clientId":
535 | if (!preg_match("/^amzn1\.application-oa2-client\.[a-z0-9]{32}$/i", $v)) {
536 | $this->_logAndThrow("Invalid parameter value for clientId.");
537 | }
538 | break;
539 | case "clientSecret":
540 | if (!preg_match("/^[a-z0-9]{64}$/i", $v)) {
541 | $this->_logAndThrow("Invalid parameter value for clientSecret.");
542 | }
543 | break;
544 | case "accessToken":
545 | if (!is_null($v)) {
546 | if (!preg_match("/^Atza(\||%7C|%7c).*$/", $v)) {
547 | $this->_logAndThrow("Invalid parameter value for accessToken.");
548 | }
549 | }
550 | break;
551 | case "refreshToken":
552 | if (!is_null($v)) {
553 | if (!preg_match("/^Atzr(\||%7C|%7c).*$/", $v)) {
554 | $this->_logAndThrow("Invalid parameter value for refreshToken.");
555 | }
556 | }
557 | break;
558 | case "sandbox":
559 | if (!is_bool($v)) {
560 | $this->_logAndThrow("Invalid parameter value for sandbox.");
561 | }
562 | break;
563 | }
564 | }
565 | return true;
566 | }
567 |
568 | private function _setEndpoints()
569 | {
570 | /* check if region exists and set api/token endpoints */
571 | if (array_key_exists(strtolower($this->config["region"]), $this->endpoints)) {
572 | $region_code = strtolower($this->config["region"]);
573 | if ($this->config["sandbox"]) {
574 | $this->endpoint = "https://{$this->endpoints[$region_code]["sandbox"]}/{$this->apiVersion}";
575 | } else {
576 | $this->endpoint = "https://{$this->endpoints[$region_code]["prod"]}/{$this->apiVersion}";
577 | }
578 | $this->tokenUrl = $this->endpoints[$region_code]["tokenUrl"];
579 | } else {
580 | $this->_logAndThrow("Invalid region.");
581 | }
582 | return true;
583 | }
584 |
585 | private function _logAndThrow($message)
586 | {
587 | error_log($message, 0);
588 | throw new \Exception($message);
589 | }
590 | }
591 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](http://unmaintained.tech/)
2 |
3 | ## Synopsis
4 |
5 | ~~Official~~ Amazon Advertising API PHP client library.
6 |
7 | This repository has been deprecated and will no longer receive updates.
8 |
9 | ## Requirements
10 |
11 | PHP >= 5.3.0
12 | cURL >= 7.18
13 |
14 | ## Documentation
15 |
16 | [API Reference](https://advertising.amazon.com/API/docs)
17 | [Access Request](https://advertising.amazon.com/API)
18 | [Getting Started](https://advertising.amazon.com/API/docs/v2/guides/get_started)
19 |
20 | ## Tutorials
21 | [Register Sandbox Profile](https://git.io/vPKMl) - This tutorial will show you how to register a profile in sandbox using CURL.
22 | [Generate and download a report using CURL](https://git.io/vPKPW) - You will need to complete registering a profile in sandbox prior to doing this tutorial.
23 |
24 | ## Sandbox self-service
25 | 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.
26 |
27 | The following country codes are available for testing.
28 |
29 | > US, CA, UK, DE, FR, ES, IT, IN, CN, JP
30 |
31 | ```PHP
32 | $client->registerProfile(array("countryCode" => "IT"));
33 | ```
34 | >
35 | ```
36 | {
37 | "registerProfileId": "5cf1aca5-4ab8-4489-8c33-013d1f85c586JP",
38 | "status": "IN_PROGRESS",
39 | "statusDetails": "Registration workflow has been started"
40 | }
41 | ```
42 |
43 | ## Quick Start
44 | #### Instantiate the client
45 | > You can pass in `accessToken` if you do not have a refresh token.
46 |
47 | ```PHP
48 | "CLIENT_ID",
55 | "clientSecret" => "CLIENT_SECRET",
56 | "refreshToken" => "REFRESH_TOKEN",
57 | "region" => "na",
58 | "sandbox" => false,
59 | );
60 |
61 | $client = new Client($config);
62 | ```
63 | #### Refresh access token
64 | > 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.
65 |
66 | ```PHP
67 | $request = $client->doRefreshToken();
68 | ```
69 |
70 | #### Get a list of profiles
71 | ```PHP
72 | $request = $client->listProfiles();
73 | ```
74 | >
75 | ```
76 | [{
77 | "profileId":1234567890,
78 | "countryCode":"US",
79 | "currencyCode":"USD",
80 | "dailyBudget":10.00,
81 | "timezone":"America/Los_Angeles",
82 | "accountInfo":{
83 | "marketplaceStringId":"ABC123",
84 | "sellerStringId":"DEF456"
85 | }]
86 | ```
87 |
88 | #### Set profile Id
89 | ```PHP
90 | $client->profileId = "1234567890";
91 | ```
92 |
93 | > Once you've set the profile Id you are ready to start making API calls.
94 |
95 | ## Example API Calls
96 |
97 | * Profiles
98 | * [listProfiles](#get-a-list-of-profiles)
99 | * [getProfile](#getprofile)
100 | * [updateProfiles](#updateprofiles)
101 | * Campaigns
102 | * [listCampaigns](#listcampaigns)
103 | * [getCampaign](#getcampaign)
104 | * [createCampaigns](#createcampaigns)
105 | * [updateCampaigns](#updatecampaigns)
106 | * [archiveCampaign](#archivecampaign)
107 | * Ad Groups
108 | * [listAdGroups](#listadgroups)
109 | * [getAdGroup](#getadgroup)
110 | * [createAdGroups](#createadgroups)
111 | * [updateAdGroups](#updateadgroups)
112 | * [archiveAdGroup](#archiveadgroup)
113 | * Biddable Keywords
114 | * [listBiddableKeywords](#listbiddablekeywords)
115 | * [getBiddableKeyword](#getbiddablekeyword)
116 | * [createBiddableKeywords](#createbiddablekeywords)
117 | * [updateBiddableKeywords](#updatebiddablekeywords)
118 | * [archiveBiddableKeyword](#archivebiddablekeyword)
119 | * Negative Keywords
120 | * [listNegativeKeywords](#listnegativekeywords)
121 | * [getNegativeKeyword](#getnegativekeyword)
122 | * [createNegativeKeywords](#createnegativekeywords)
123 | * [updateNegativeKeywords](#updatenegativekeywords)
124 | * [archiveNegativeKeyword](#archivenegativekeyword)
125 | * Campaign Negative Keywords
126 | * [listCampaignNegativeKeywords](#listcampaignnegativekeywords)
127 | * [getCampaignNegativeKeyword](#getcampaignnegativekeyword)
128 | * [createCampaignNegativeKeywords](#createcampaignnegativekeywords)
129 | * [updateCampaignNegativeKeywords](#updatecampaignnegativekeywords)
130 | * [removeCampaignNegativeKeyword](#removecampaignnegativekeyword)
131 | * Product Ads
132 | * [listProductAds](#listproductads)
133 | * [getProductAd](#getproductad)
134 | * [createProductAds](#createproductads)
135 | * [updateProductAds](#updateproductads)
136 | * [archiveProductAd](#archiveproductad)
137 | * Snapshots
138 | * [requestSnapshot](#requestsnapshot)
139 | * [getSnapshot](#getsnapshot)
140 | * Reports
141 | * [requestReport](#requestreport)
142 | * [getReport](#getreport)
143 | * Bid Recommendations
144 | * [getAdGroupBidRecommendations](#getadgroupbidrecommendations)
145 | * [getKeywordBidRecommendations](#getkeywordbidrecommendations)
146 | * [bulkGetKeywordBidRecommendations](#bulkgetkeywordbidrecommendations)
147 | * Keyword Suggestions
148 | * [getAdGroupKeywordSuggestions](#getadgroupkeywordsuggestions)
149 | * [getAdGroupKeywordSuggestionsEx](#getadgroupkeywordsuggestionsex)
150 | * [getAsinKeywordSuggestions](#getasinkeywordsuggestions)
151 | * [bulkGetAsinKeywordSuggestions](#bulkgetasinkeywordsuggestions)
152 |
153 | #### getProfile
154 | > Retrieves a single profile by Id.
155 |
156 | ```PHP
157 | $client->getProfile("1234567890");
158 | ```
159 | >
160 | ```
161 | {
162 | "profileId": 1234567890,
163 | "countryCode": "US",
164 | "currencyCode": "USD",
165 | "dailyBudget": 3.99,
166 | "timezone": "America/Los_Angeles",
167 | "accountInfo": {
168 | "marketplaceStringId": "ABC123",
169 | "sellerStringId": "DEF456"
170 | }
171 | }
172 | ```
173 |
174 | ---
175 | #### updateProfiles
176 | > Updates one or more profiles. Advertisers are identified using their `profileIds`.
177 |
178 | ```PHP
179 | $client->updateProfiles(
180 | array(
181 | array(
182 | "profileId" => $client->profileId,
183 | "dailyBudget" => 3.99),
184 | array(
185 | "profileId" => 11223344,
186 | "dailyBudget" => 6.00)));
187 |
188 | ```
189 | >
190 | ```
191 | [
192 | {
193 | "code": "SUCCESS",
194 | "profileId": 1234567890
195 | },
196 | {
197 | "code": "NOT_FOUND",
198 | "description": "Profile with id 11223344 was not found for this advertiser.",
199 | "profileId": 0
200 | }
201 | ]
202 | ```
203 |
204 | ---
205 | #### listCampaigns
206 | > Retrieves a list of campaigns satisfying optional criteria.
207 |
208 | ```PHP
209 | $client->listCampaigns(array("stateFilter" => "enabled"));
210 | ```
211 | >
212 | ```
213 | [
214 | {
215 | "campaignId": 59836775211065,
216 | "name": "CampaignOne",
217 | "campaignType": "sponsoredProducts",
218 | "targetingType": "manual",
219 | "dailyBudget": 15.0,
220 | "startDate": "20160330",
221 | "state": "enabled"
222 | },
223 | {
224 | "campaignId": 254238342004647,
225 | "name": "CampaignTwo",
226 | "campaignType": "sponsoredProducts",
227 | "targetingType": "manual",
228 | "dailyBudget": 5.0,
229 | "startDate": "20160510",
230 | "state": "enabled"
231 | }
232 | ]
233 | ```
234 |
235 | ---
236 | #### getCampaign
237 | > Retrieves a campaign by Id. Note that this call returns the minimal set of campaign fields, but is more efficient than `getCampaignEx`.
238 |
239 | ```PHP
240 | $client->getCampaign(1234567890);
241 | ```
242 | >
243 | ```
244 | {
245 | "campaignId": 1234567890,
246 | "name": "CampaignOne",
247 | "campaignType": "sponsoredProducts",
248 | "targetingType": "manual",
249 | "dailyBudget": 15.0,
250 | "startDate": "20160330",
251 | "state": "enabled"
252 | }
253 | ```
254 |
255 | ---
256 | #### createCampaigns
257 | > Creates one or more campaigns. Successfully created campaigns will be assigned unique `campaignId`s.
258 |
259 | ```PHP
260 | $client->createCampaigns(
261 | array(
262 | array("name" => "My Campaign One",
263 | "campaignType" => "sponsoredProducts",
264 | "targetingType" => "manual",
265 | "state" => "enabled",
266 | "dailyBudget" => 5.00,
267 | "startDate" => date("Ymd")),
268 | array("name" => "My Campaign Two",
269 | "campaignType" => "sponsoredProducts",
270 | "targetingType" => "manual",
271 | "state" => "enabled",
272 | "dailyBudget" => 15.00,
273 | "startDate" => date("Ymd"))));
274 | ```
275 | >
276 | ```
277 | [
278 | {
279 | "code": "SUCCESS",
280 | "campaignId": 173284463890123
281 | },
282 | {
283 | "code": "SUCCESS",
284 | "campaignId": 27074907785456
285 | }
286 | ]
287 | ```
288 |
289 | ---
290 | #### updateCampaigns
291 | > Updates one or more campaigns. Campaigns are identified using their `campaignId`s.
292 |
293 | ```PHP
294 | $client->updateCampaigns(
295 | array(
296 | array("campaignId" => 173284463890123,
297 | "name" => "Update Campaign One",
298 | "state" => "enabled",
299 | "dailyBudget" => 10.99),
300 | array("campaignId" => 27074907785456,
301 | "name" => "Update Campaign Two",
302 | "state" => "enabled",
303 | "dailyBudget" => 99.99)));
304 | ```
305 | >
306 | ```
307 | [
308 | {
309 | "code": "SUCCESS",
310 | "campaignId": 173284463890123
311 | },
312 | {
313 | "code": "SUCCESS",
314 | "campaignId": 27074907785456
315 | }
316 | ]
317 | ```
318 |
319 | ---
320 | #### archiveCampaign
321 | > Sets the campaign status to archived. This same operation can be performed via an update, but is included for completeness.
322 |
323 | ```PHP
324 | $client->archiveCampaign(1234567890);
325 | ```
326 | >
327 | ```
328 | {
329 | "code": "SUCCESS",
330 | "campaignId": 1234567890
331 | }
332 | ```
333 |
334 | ---
335 | #### listAdGroups
336 | > Retrieves a list of ad groups satisfying optional criteria.
337 |
338 | ```PHP
339 | $client->listAdGroups(array("stateFilter" => "enabled"));
340 | ```
341 | >
342 | ```
343 | [
344 | {
345 | "adGroupId": 262960563101486,
346 | "name": "AdGroup One",
347 | "campaignId": 181483024866689,
348 | "defaultBid": 1.0,
349 | "state": "enabled"
350 | },
351 | {
352 | "adGroupId": 52169162825843,
353 | "name": "AdGroup Two",
354 | "campaignId": 250040549047739,
355 | "defaultBid": 2.0,
356 | "state": "enabled"
357 | }
358 | ]
359 | ```
360 |
361 | ---
362 | #### getAdGroup
363 | > Retrieves an ad group by Id. Note that this call returns the minimal set of ad group fields, but is more efficient than `getAdGroupEx`.
364 |
365 | ```PHP
366 | $client->getAdGroup(262960563101486);
367 | ```
368 | >
369 | ```
370 | {
371 | "adGroupId": 262960563101486,
372 | "name": "AdGroup One",
373 | "campaignId": 181483024866689,
374 | "defaultBid": 1.0,
375 | "state": "enabled"
376 | }
377 | ```
378 |
379 | ---
380 | #### createAdGroups
381 | > Creates one or more ad groups. Successfully created ad groups will be assigned unique `adGroupId`s.
382 |
383 | ```PHP
384 | $client->createAdGroups(
385 | array(
386 | array(
387 | "campaignId" => 250040549047739,
388 | "name" => "New AdGroup One",
389 | "state" => "enabled",
390 | "defaultBid" => 2.0),
391 | array(
392 | "campaignId" => 59836775211065,
393 | "name" => "New AdGroup Two",
394 | "state" => "enabled",
395 | "defaultBid" => 5.0)));
396 | ```
397 | >
398 | ```
399 | [
400 | {
401 | "code": "SUCCESS",
402 | "adGroupId": 117483076163518
403 | },
404 | {
405 | "code": "SUCCESS",
406 | "adGroupId": 123431426718271
407 | }
408 | ]
409 | ```
410 |
411 | ---
412 | #### updateAdGroups
413 | > Updates one or more ad groups. Ad groups are identified using their `adGroupId`s.
414 |
415 | ```PHP
416 | $client->updateAdGroups(
417 | array(
418 | array(
419 | "adGroupId" => 117483076163518,
420 | "state" => "enabled",
421 | "defaultBid" => 20.0),
422 | array(
423 | "adGroupId" => 123431426718271,
424 | "state" => "enabled",
425 | "defaultBid" => 15.0)));
426 | ```
427 | >
428 | ```
429 | [
430 | {
431 | "code": "SUCCESS",
432 | "adGroupId": 117483076163518
433 | },
434 | {
435 | "code": "SUCCESS",
436 | "adGroupId": 123431426718271
437 | }
438 | ]
439 | ```
440 |
441 | ---
442 | #### archiveAdGroup
443 | > Sets the ad group status to archived. This same operation can be performed via an update, but is included for completeness.
444 |
445 | ```PHP
446 | $client->archiveAdGroup(117483076163518);
447 | ```
448 | >
449 | ```
450 | {
451 | "code": "SUCCESS",
452 | "adGroupId": 117483076163518
453 | }
454 | ```
455 |
456 | ---
457 | #### listBiddableKeywords
458 | > Retrieves a list of keywords satisfying optional criteria.
459 |
460 | ```PHP
461 | $client->listBiddableKeywords(array("stateFilter" => "enabled"));
462 | ```
463 | >
464 | ```
465 | [
466 | {
467 | "keywordId": 174140697976855,
468 | "adGroupId": 52169162825843,
469 | "campaignId": 250040549047739,
470 | "keywordText": "KeywordOne",
471 | "matchType": "exact",
472 | "state": "enabled"
473 | },
474 | {
475 | "keywordId": 118195812188994,
476 | "adGroupId": 52169162825843,
477 | "campaignId": 250040549047739,
478 | "keywordText": "KeywordTwo",
479 | "matchType": "exact",
480 | "state": "enabled"
481 | }
482 | ]
483 | ```
484 |
485 | ---
486 | #### getBiddableKeyword
487 | > Retrieves a keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than getBiddableKeywordEx.
488 |
489 | ```PHP
490 | $client->getBiddableKeyword(174140697976855);
491 | ```
492 | >
493 | ```
494 | {
495 | "keywordId": 174140697976855,
496 | "adGroupId": 52169162825843,
497 | "campaignId": 250040549047739,
498 | "keywordText": "KeywordOne",
499 | "matchType": "exact",
500 | "state": "enabled"
501 | }
502 | ```
503 |
504 | ---
505 | #### createBiddableKeywords
506 | > Creates one or more keywords. Successfully created keywords will be assigned unique `keywordId`s.
507 |
508 | ```PHP
509 | $client->createBiddableKeywords(
510 | array(
511 | array(
512 | "campaignId" => 250040549047739,
513 | "adGroupId" => 52169162825843,
514 | "keywordText" => "AnotherKeyword",
515 | "matchType" => "exact",
516 | "state" => "enabled"),
517 | array(
518 | "campaignId" => 250040549047739,
519 | "adGroupId" => 52169162825843,
520 | "keywordText" => "YetAnotherKeyword",
521 | "matchType" => "exact",
522 | "state" => "enabled")));
523 | ```
524 | >
525 | ```
526 | [
527 | {
528 | "code": "SUCCESS",
529 | "keywordId": 112210768353976
530 | },
531 | {
532 | "code": "SUCCESS",
533 | "keywordId": 249490346605943
534 | }
535 | ]
536 | ```
537 |
538 | ---
539 | #### updateBiddableKeywords
540 | > Updates one or more keywords. Keywords are identified using their `keywordId`s.
541 |
542 | ```PHP
543 | $client->updateBiddableKeywords(
544 | array(
545 | array(
546 | "keywordId" => 112210768353976,
547 | "bid" => 100.0,
548 | "state" => "archived"),
549 | array(
550 | "keywordId" => 249490346605943,
551 | "bid" => 50.0,
552 | "state" => "archived")));
553 | ```
554 | >
555 | ```
556 | [
557 | {
558 | "code": "SUCCESS",
559 | "keywordId": 112210768353976
560 | },
561 | {
562 | "code": "SUCCESS",
563 | "keywordId": 249490346605943
564 | }
565 | ]
566 | ```
567 |
568 | ---
569 | #### archiveBiddableKeyword
570 | > Sets the keyword status to archived. This same operation can be performed via an update, but is included for completeness.
571 |
572 | ```PHP
573 | $client->archiveBiddableKeyword(112210768353976);
574 | ```
575 | >
576 | ```
577 | {
578 | "code": "200",
579 | "requestId": "0TR95PJD6Z16FFCZDXD0"
580 | }
581 | ```
582 |
583 | ---
584 | #### listNegativeKeywords
585 | > Retrieves a list of negative keywords satisfying optional criteria.
586 |
587 | ```PHP
588 | $client->listNegativeKeywords(array("stateFilter" => "enabled"));
589 | ```
590 | >
591 | ```
592 | [
593 | {
594 | "keywordId": 281218602770639,
595 | "adGroupId": 52169162825843,
596 | "campaignId": 250040549047739,
597 | "keywordText": "KeywordOne",
598 | "matchType": "negativeExact",
599 | "state": "enabled"
600 | },
601 | {
602 | "keywordId": 280875877064090,
603 | "adGroupId": 262960563101486,
604 | "campaignId": 181483024866689,
605 | "keywordText": "KeywordTwo",
606 | "matchType": "negativeExact",
607 | "state": "enabled"
608 | }
609 | ]
610 | ```
611 |
612 | ---
613 | #### getNegativeKeyword
614 | > Retrieves a negative keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than `getNegativeKeywordEx`.
615 |
616 | ```PHP
617 | $client->getNegativeKeyword(281218602770639);
618 | ```
619 | >
620 | ```
621 | {
622 | "keywordId": 281218602770639,
623 | "adGroupId": 52169162825843,
624 | "campaignId": 250040549047739,
625 | "keywordText": "KeywordOne",
626 | "matchType": "negativeExact",
627 | "state": "enabled"
628 | }
629 | ```
630 |
631 | ---
632 | #### createNegativeKeywords
633 | > Creates one or more negative keywords. Successfully created keywords will be assigned unique keywordIds.
634 |
635 | ```PHP
636 | $client->createNegativeKeywords(
637 | array(
638 | array(
639 | "campaignId" => 250040549047739,
640 | "adGroupId" => 52169162825843,
641 | "keywordText" => "AnotherKeyword",
642 | "matchType" => "negativeExact",
643 | "state" => "enabled"),
644 | array(
645 | "campaignId" => 181483024866689,
646 | "adGroupId" => 262960563101486,
647 | "keywordText" => "YetAnotherKeyword",
648 | "matchType" => "negativeExact",
649 | "state" => "enabled")));
650 | ```
651 | >
652 | ```
653 | [
654 | {
655 | "code": "SUCCESS",
656 | "keywordId": 61857817062026
657 | },
658 | {
659 | "code": "SUCCESS",
660 | "keywordId": 147623067066967
661 | }
662 | ]
663 | ```
664 |
665 | ---
666 | #### updateNegativeKeywords
667 | > Updates one or more negative keywords. Keywords are identified using their `keywordId`s.
668 |
669 | ```PHP
670 | $client->updateNegativeKeywords(
671 | array(
672 | array(
673 | "keywordId" => 61857817062026,
674 | "state" => "enabled",
675 | "bid" => 15.0),
676 | array(
677 | "keywordId" => 61857817062026,
678 | "state" => "enabled",
679 | "bid" => 20.0)));
680 | ```
681 | >
682 | ```
683 | [
684 | {
685 | "code": "SUCCESS",
686 | "keywordId": 61857817062026
687 | },
688 | {
689 | "code": "INVALID_ARGUMENT",
690 | "description": "Entity with id 61857817062026 already specified in this update operation."
691 | }
692 | ]
693 | ```
694 |
695 | ---
696 | #### archiveNegativeKeyword
697 | > Sets the negative keyword status to archived. This same operation can be performed via an update to the status, but is included for completeness.
698 |
699 | ```PHP
700 | $client->archiveNegativeKeyword(61857817062026);
701 | ```
702 | >
703 | ```
704 | {
705 | "code": "SUCCESS",
706 | "keywordId": 61857817062026
707 | }
708 | ```
709 |
710 | ---
711 | #### listCampaignNegativeKeywords
712 | > Retrieves a list of negative campaign keywords satisfying optional criteria.
713 |
714 | ```PHP
715 | $client->listCampaignNegativeKeywords(array("matchTypeFilter" => "negativeExact"));
716 | ```
717 | >
718 | ```
719 | [
720 | {
721 | "keywordId": 131747786239884,
722 | "adGroupId": null,
723 | "campaignId": 181483024866689,
724 | "keywordText": "Negative Keyword",
725 | "matchType": "negativeExact",
726 | "state": "enabled"
727 | },
728 | {
729 | "keywordId": 197201372210821,
730 | "adGroupId": null,
731 | "campaignId": 181483024866689,
732 | "keywordText": "My Negative Keyword",
733 | "matchType": "negativeExact",
734 | "state": "enabled"
735 | }
736 | ]
737 | ```
738 |
739 | ---
740 | #### getCampaignNegativeKeyword
741 | > Retrieves a campaign negative keyword by Id. Note that this call returns the minimal set of keyword fields, but is more efficient than `getCampaignNegativeKeywordEx`.
742 |
743 | ```PHP
744 | $client->getCampaignNegativeKeyword(197201372210821);
745 | ```
746 | >
747 | ```
748 | {
749 | "keywordId": 197201372210821,
750 | "adGroupId": null,
751 | "campaignId": 181483024866689,
752 | "keywordText": "My Negative Keyword",
753 | "matchType": "negativeExact",
754 | "state": "enabled"
755 | }
756 | ```
757 |
758 | ---
759 | #### createCampaignNegativeKeywords
760 | > Creates one or more campaign negative keywords. Successfully created keywords will be assigned unique `keywordId`s.
761 |
762 | ```PHP
763 | $client->createCampaignNegativeKeywords(
764 | array(
765 | array(
766 | "campaignId" => 181483024866689,
767 | "keywordText" => "Negative Keyword One",
768 | "matchType" => "negativeExact",
769 | "state" => "enabled"),
770 | array(
771 | "campaignId" => 181483024866689,
772 | "keywordText" => "Negative Keyword Two",
773 | "matchType" => "negativeExact",
774 | "state" => "enabled")));
775 | ```
776 | >
777 | ```
778 | [
779 | {
780 | "code": "SUCCESS",
781 | "keywordId": 196797670902082
782 | },
783 | {
784 | "code": "SUCCESS",
785 | "keywordId": 186203479904657
786 | }
787 | ]
788 | ```
789 |
790 | ---
791 | #### updateCampaignNegativeKeywords
792 | > Updates one or more campaign negative keywords. Keywords are identified using their `keywordId`s.
793 |
794 | > Campaign negative keywords can currently only be removed.
795 |
796 | ---
797 | #### removeCampaignNegativeKeyword
798 | > 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.
799 |
800 | ```PHP
801 | $client->removeCampaignNegativeKeyword(186203479904657);
802 | ```
803 | >
804 | ```
805 | {
806 | "code": "SUCCESS",
807 | "keywordId": 186203479904657
808 | }
809 | ```
810 |
811 | ---
812 | #### listProductAds
813 | > Retrieves a list of product ads satisfying optional criteria.
814 |
815 | ```PHP
816 | $client->listProductAds(array("stateFilter" => "enabled"));
817 | ```
818 | >
819 | ```
820 | [
821 | {
822 | "adId": 247309761200483,
823 | "adGroupId": 262960563101486,
824 | "campaignId": 181483024866689,
825 | "sku": "TEST001",
826 | "state": "enabled"
827 | }
828 | ]
829 | ```
830 |
831 | ---
832 | #### getProductAd
833 | > Retrieves a product ad by Id. Note that this call returns the minimal set of product ad fields, but is more efficient than `getProductAdEx`.
834 |
835 | ```PHP
836 | $client->getProductAd(247309761200483);
837 | ```
838 | >
839 | ```
840 | {
841 | "adId": 247309761200483,
842 | "adGroupId": 262960563101486,
843 | "campaignId": 181483024866689,
844 | "sku": "TEST001",
845 | "state": "enabled"
846 | }
847 | ```
848 |
849 | ---
850 | #### createProductAds
851 | > Creates one or more product ads. Successfully created product ads will be assigned unique `adId`s.
852 |
853 | ```PHP
854 | $client->createProductAds(
855 | array(
856 | array(
857 | "campaignId" => 181483024866689,
858 | "adGroupId" => 262960563101486,
859 | "sku" => "TEST002",
860 | "state" => "enabled"),
861 | array(
862 | "campaignId" => 181483024866689,
863 | "adGroupId" => 262960563101486,
864 | "sku" => "TEST003",
865 | "state" => "enabled")));
866 | ```
867 | >
868 | ```
869 | [
870 | {
871 | "code": "SUCCESS",
872 | "adId": 239870616623537
873 | },
874 | {
875 | "code": "SUCCESS",
876 | "adId": 191456410590622
877 | }
878 | ]
879 | ```
880 |
881 | ---
882 | #### updateProductAds
883 | > Updates one or more product ads. Product ads are identified using their `adId`s.
884 |
885 | ```PHP
886 | $client->updateProductAds(
887 | array(
888 | array(
889 | "adId" => 239870616623537,
890 | "state" => "archived"),
891 | array(
892 | "adId" => 191456410590622,
893 | "state" => "archived")));
894 | ```
895 | >
896 | ```
897 | [
898 | {
899 | "code": "SUCCESS",
900 | "adId": 239870616623537
901 | },
902 | {
903 | "code": "SUCCESS",
904 | "adId": 191456410590622
905 | }
906 | ]
907 | ```
908 |
909 | ---
910 | #### archiveProductAd
911 | > Sets the product ad status to archived. This same operation can be performed via an update, but is included for completeness.
912 |
913 | ```PHP
914 | $client->archiveProductAd(239870616623537);
915 | ```
916 | >
917 | ```
918 | {
919 | "code": "SUCCESS",
920 | "adId": 239870616623537
921 | }
922 | ```
923 |
924 | ---
925 | #### requestSnapshot
926 | > Request a snapshot report for all entities of a single type.
927 |
928 | ```PHP
929 | $client->requestSnapshot(
930 | "campaigns",
931 | array("stateFilter" => "enabled,paused,archived",
932 | "campaignType" => "sponsoredProducts"));
933 | ```
934 | >
935 | ```
936 | {
937 | "snapshotId": "amzn1.clicksAPI.v1.p1.573A0477.ec41773a-1659-4013-8eb9-fa18c87ef5df",
938 | "recordType": "campaign",
939 | "status": "IN_PROGRESS"
940 | }
941 | ```
942 |
943 | ---
944 | #### getSnapshot
945 | > Retrieve a previously requested report.
946 |
947 | ```PHP
948 | $client->getSnapshot("amzn1.clicksAPI.v1.p1.573A0477.ec41773a-1659-4013-8eb9-fa18c87ef5df");
949 | ```
950 | >
951 | ```
952 | [
953 | {
954 | "campaignId": 181483024866689,
955 | "name": "Campaign One",
956 | "campaignType": "sponsoredProducts",
957 | "targetingType": "manual",
958 | "dailyBudget": 5.0,
959 | "startDate": "20160330",
960 | "state": "archived"
961 | },
962 | {
963 | "campaignId": 59836775211065,
964 | "name": "Campaign Two",
965 | "campaignType": "sponsoredProducts",
966 | "targetingType": "manual",
967 | "dailyBudget": 10.99,
968 | "startDate": "20160330",
969 | "state": "archived"
970 | },
971 | {
972 | "campaignId": 254238342004647,
973 | "name": "Campaign Three",
974 | "campaignType": "sponsoredProducts",
975 | "targetingType": "manual",
976 | "dailyBudget": 99.99,
977 | "startDate": "20160510",
978 | "state": "enabled"
979 | }
980 | ]
981 | ```
982 |
983 | ---
984 | #### requestReport
985 | > Request a customized performance report for all entities of a single type which have performance data to report.
986 |
987 | ```PHP
988 | $client->requestReport(
989 | "campaigns",
990 | array("reportDate" => "20160515",
991 | "campaignType" => "sponsoredProducts",
992 | "metrics" => "impressions,clicks,cost"));
993 | ```
994 | >
995 | ```
996 | {
997 | "reportId": "amzn1.clicksAPI.v1.m1.573A0808.32908def-66a1-4ce2-8f12-780dc4ae1d43",
998 | "recordType": "campaign",
999 | "status": "IN_PROGRESS",
1000 | "statusDetails": "Report is submitted"
1001 | }
1002 | ```
1003 |
1004 | ---
1005 | #### getReport
1006 | > Retrieve a previously requested report.
1007 |
1008 | ```PHP
1009 | $client->getReport("amzn1.clicksAPI.v1.m1.573A0808.32908def-66a1-4ce2-8f12-780dc4ae1d43");
1010 | ```
1011 | > Sandbox will return dummy data.
1012 | ```
1013 | [
1014 | {
1015 | "cost": 647.75,
1016 | "campaignId": 230751293360275,
1017 | "clicks": 2591,
1018 | "impressions": 58288
1019 | },
1020 | {
1021 | "cost": 619.5,
1022 | "campaignId": 52110033002744,
1023 | "clicks": 2478,
1024 | "impressions": 68408
1025 | },
1026 | {
1027 | "cost": 151.91,
1028 | "campaignId": 140739567440917,
1029 | "clicks": 633,
1030 | "impressions": 17343
1031 | },
1032 | {
1033 | "cost": 143.46,
1034 | "campaignId": 79132327246328,
1035 | "clicks": 797,
1036 | "impressions": 48903
1037 | }
1038 | ]
1039 | ```
1040 |
1041 | ---
1042 | #### getAdGroupBidRecommendations
1043 | > Request bid recommendations for specified ad group.
1044 |
1045 | ```PHP
1046 | $client->getAdGroupBidRecommendations(1234509876);
1047 | ```
1048 | >
1049 | ```
1050 | {
1051 | "adGroupId": 1234509876,
1052 | "suggestedBid": {
1053 | "rangeEnd": 2.16,
1054 | "rangeStart": 0.67,
1055 | "suggested": 1.67
1056 | }
1057 | }
1058 | ```
1059 |
1060 | ---
1061 | #### getKeywordBidRecommendations
1062 | > Request bid recommendations for specified keyword.
1063 |
1064 | ```PHP
1065 | $client->getKeywordBidRecommendations(85243141758914);
1066 | ```
1067 | >
1068 | ```
1069 | {
1070 | "keywordId": 85243141758914,
1071 | "adGroupId": 252673310548066,
1072 | "suggestedBid": {
1073 | "rangeEnd": 3.18,
1074 | "rangeStart": 0.35,
1075 | "suggested": 2.97
1076 | }
1077 | }
1078 | ```
1079 |
1080 | ---
1081 | #### bulkGetKeywordBidRecommendations
1082 | > Request bid recommendations for a list of up to 100 keywords.
1083 |
1084 | ```PHP
1085 | $client->bulkGetKeywordBidRecommendations(
1086 | 242783265349805,
1087 | array(
1088 | array("keyword" => "testKeywordOne",
1089 | "matchType" => "exact"),
1090 | array("keyword" => "testKeywordTwo",
1091 | "matchType" => "exact")
1092 | ));
1093 | ```
1094 | >
1095 | ```
1096 | {
1097 | "adGroupId": 242783265349805,
1098 | "recommendations": [
1099 | {
1100 | "code": "SUCCESS",
1101 | "keyword": "testKeywordOne",
1102 | "matchType": "exact",
1103 | "suggestedBid": {
1104 | "rangeEnd": 2.67,
1105 | "rangeStart": 0.38,
1106 | "suggested": 2.07
1107 | }
1108 | },
1109 | {
1110 | "code": "SUCCESS",
1111 | "keyword": "testKeywordTwo",
1112 | "matchType": "exact",
1113 | "suggestedBid": {
1114 | "rangeEnd": 3.19,
1115 | "rangeStart": 0.79,
1116 | "suggested": 3.03
1117 | }
1118 | }
1119 | ]
1120 | }
1121 | ```
1122 |
1123 | ---
1124 | #### getAdGroupKeywordSuggestions
1125 | > Request keyword suggestions for specified ad group.
1126 |
1127 | ```PHP
1128 | $client->getAdGroupKeywordSuggestions(
1129 | array("adGroupId" => 1234567890,
1130 | "maxNumSuggestions" => 2,
1131 | "adStateFilter" => "enabled"));
1132 | ```
1133 | >
1134 | ```
1135 | {
1136 | "adGroupId": 1234567890,
1137 | "suggestedKeywords": [
1138 | {
1139 | "keywordText": "keyword PRODUCT_AD_A 1",
1140 | "matchType": "broad"
1141 | },
1142 | {
1143 | "keywordText": "keyword PRODUCT_AD_B 1",
1144 | "matchType": "broad"
1145 | }
1146 | ]
1147 | }
1148 | ```
1149 |
1150 | ---
1151 | #### getAdGroupKeywordSuggestionsEx
1152 | > Request keyword suggestions for specified ad group, extended version. Adds the ability to return bid recommendation for returned keywords.
1153 |
1154 | ```PHP
1155 | $client->getAdGroupKeywordSuggestionsEx(
1156 | array("adGroupId" => 1234567890,
1157 | "maxNumSuggestions" => 2,
1158 | "suggestBids" => "yes",
1159 | "adStateFilter" => "enabled"));
1160 | ```
1161 | >
1162 | ```
1163 | [
1164 | {
1165 | "adGroupId": 1234567890,
1166 | "campaignId": 0987654321,
1167 | "keywordText": "keyword TESTASINXX 1",
1168 | "matchType": "broad",
1169 | "state": "enabled",
1170 | "bid": 1.84
1171 | },
1172 | {
1173 | "adGroupId": 1234567890,
1174 | "campaignId": 0987654321,
1175 | "keywordText": "keyword TESTASINXX 2",
1176 | "matchType": "broad",
1177 | "state": "enabled",
1178 | "bid": 1.07
1179 | }
1180 | ]
1181 | ```
1182 |
1183 | ---
1184 | #### getAsinKeywordSuggestions
1185 | > Request keyword suggestions for specified asin.
1186 |
1187 | ```PHP
1188 | $client->getAsinKeywordSuggestions(
1189 | array("asin" => "B00IJSNPM0",
1190 | "maxNumSuggestions" => 2));
1191 | ```
1192 | >
1193 | ```
1194 | [
1195 | {
1196 | "keywordText": "keyword B00IJSNPM0 1",
1197 | "matchType": "broad"
1198 | },
1199 | {
1200 | "keywordText": "keyword B00IJSNPM0 2",
1201 | "matchType": "broad"
1202 | }
1203 | ]
1204 | ```
1205 |
1206 | ---
1207 | #### bulkGetAsinKeywordSuggestions
1208 | > Request keyword suggestions for a list of asin.
1209 |
1210 | ```PHP
1211 | $client->bulkGetAsinKeywordSuggestions(
1212 | array("asins" => array(
1213 | "B00IJSNPM0",
1214 | "B00IJSO1NM"),
1215 | "maxNumSuggestions" => 2));
1216 | ```
1217 | >
1218 | ```
1219 | [
1220 | {
1221 | "keywordText": "keyword B00IJSNPM0 1",
1222 | "matchType": "broad"
1223 | },
1224 | {
1225 | "keywordText": "keyword B00IJSO1NM 1",
1226 | "matchType": "broad"
1227 | }
1228 | ]
1229 | ```
1230 |
--------------------------------------------------------------------------------