Hi,
I'm trying to pull 5 stores and for each of them read the
transactions. The 5-store pull works fine, but for the transactions I
get an OAuth error, since it's private data. How do I access the
Sandbox? I tried changing the URL from
http://openapi.etsy.com/v2/... to
http://sandbox.openapi.etsy.com/v2/...,
but that did nothing.
Below is my PHP. Look for the line "// **** here's the error..."
Thanks.
<?php
$url = "
http://openapi.etsy.com/v2/shops?limit=5&api_key=xxx";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (intval($status) != 200)
{
throw new Exception("HTTP $status\n$response_body");
}
$response = json_decode($response_body);
$shopIDArray = array();
$shopNameArray = array();
$shopListingsActiveCountArray = array();
$shopNumFavorersArray = array();
$shopURLArray = array();
for($k=0; $k<5; $k++)
{
$shop = $response->results[$k];
if (!isset($shop->shop_id))
{
throw new RuntimeException("Shop Resource doesn't have field
shop_id");
}
$shopID = $shop->shop_id;
$shopIDArray[$k] = $shopID;
$shopNameArray[ $shopID ] = $shop->shop_name;
$shopListingsActiveCountArray[ $shopID ] = $shop-
>listing_active_count;
$shopNumFavorersArray[ $shopID ] = $shop->num_favorers;
}
// Sample (one) transaction from each store
print("<table>");
print("<tr><td>transaction_id</td><td>price</td><td>quantity</
td><td>transaction_type</td></tr>");
for($j=0; $j<5; $j++)
{
$shopID = $shopIDArray[$j];
print("<tr><td colspan=4>ShopID: $shopID</td></tr>");
$txnurl = "
http://openapi.etsy.com/v2/private/shops/". $shopID. "/
transactions?api_key=xxx";
$ch = curl_init($txnurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// **** here's the error: Fatal error: Uncaught exception 'Exception'
with message 'HTTP 403 This method requires authentication.
if (intval($status) != 200)
{
throw new Exception("HTTP $status\n$response_body");
}
$txnresponse = json_decode($response_body);
$txn = $txnresponse->results[0];
print("<tr>");
print("<td>$txn->transaction_id</td>");
print("<td>$txn->price</td>");
print("<td>$txn->quantity</td>");
print("<td>$txn->transaction_type</td>");
print("</tr>");
}
print("</table>");