Skip to content

Instantly share code, notes, and snippets.

View dbrent-amazon's full-sized avatar

Brent dbrent-amazon

  • Amazon
  • Seattle, WA
View GitHub Profile
@dbrent-amazon
dbrent-amazon / generate-access-token
Created August 15, 2018 18:10
generate-access-token
curl \
-H "Content-Type:application/x-www-form-urlencoded;charset=UTF-8" \
-d "grant_type=refresh_token&client_id=YOUR_CLIENT_ID&refresh_token=YOUR_REFRESH_TOKEN&client_secret=YOUR_CLIENT_SECRET" \
https://api.amazon.com/auth/o2/token
@dbrent-amazon
dbrent-amazon / jsonPrettyPrint.php
Created June 20, 2017 19:19
phpJsonPrettyPrint
<?php
function jsonPrettyPrint($request)
{
$json = $request["response"];
$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = null;
Note that this is sandbox. If you have not registered profiles in sandbox you
will need to do so prior to making these calls. You will also need at least
one campaign, ad group, and keyword before you see anything in the report.
While in sandbox, we will return “dummy” data so that you can see how an actual
report would look.
To make it look nicer, I always export my access token prior to making calls.
You could do the same for API-Scope (profile Id) if you wish. Make sure to use
quotes around the access token if it isn’t URL encoded. It has a | (pipe)
symbol and your shell won’t like it.
/* requestReport */
$req = $client->requestReport(
"productAds",
array("reportDate" => "20160916",
"campaignType" => "sponsoredProducts",
"metrics" => "impressions,clicks,cost,attributedConversions30dSameSKU,attributedConversions30d,attributedSales30dSameSKU,attributedSales30d"));
/* getReport */
$req = $client->getReport("REPORT_ID");
file_put_contents("/Users/dbrent/Downloads/report.json", $req["response"]);
Amazon Advertising API
Example API call to self-register for sandbox access. Country code can be one of the following:
US, CA, UK, DE, FR, ES, IT, IN, CN, JP
curl -X PUT \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
filetype off
execute pathogen#infect()
set nocompatible
filetype indent plugin on
syntax on
colo fraket
set modeline
set number
set tabstop=4
@dbrent-amazon
dbrent-amazon / InstantPaymentNotification.py
Last active October 2, 2015 19:15
InstantPaymentNotification (Flask)
from flask import request
@app.route('/ipn_handler', methods=['GET', 'POST'])
def ipn_handler():
from pay_with_amazon.ipn_handler import IpnHandler
response = IpnHandler(request.data, request.headers)
if response.authenticate():
return(response.to_json())
else:
@dbrent-amazon
dbrent-amazon / GetAuthorizationDetails.py
Created October 2, 2015 18:56
GetAuthorizationDetails
from pay_with_amazon.client import PayWithAmazonClient
client = PayWithAmazonClient(
mws_access_key='YOUR_ACCESS_KEY',
mws_secret_key='YOUR_SECRET_KEY',
merchant_id='YOUR_MERCHANT_ID',
region='na',
currency_code='USD')
response = client.get_authorization_details(
@dbrent-amazon
dbrent-amazon / AuthorizeSimulation.py
Created October 2, 2015 18:54
AuthorizeSimulation
from pay_with_amazon.client import PayWithAmazonClient
client = PayWithAmazonClient(
mws_access_key='YOUR_ACCESS_KEY',
mws_secret_key='YOUR_SECRET_KEY',
merchant_id='YOUR_MERCHANT_ID',
region='na',
currency_code='USD')
response = client.authorize(
@dbrent-amazon
dbrent-amazon / CloseAuthorization.py
Last active October 2, 2015 19:16
CloseAuthorization
from pay_with_amazon.client import PayWithAmazonClient
client = PayWithAmazonClient(
mws_access_key='YOUR_ACCESS_KEY',
mws_secret_key='YOUR_SECRET_KEY',
merchant_id='YOUR_MERCHANT_ID',
region='na',
currency_code='USD')
response = client.close_authorization(