How to access Sandbox for OAuth calls

56 views
Skip to first unread message

David

unread,
May 19, 2012, 7:28:09 PM5/19/12
to Etsy API V2
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>");

David

unread,
May 25, 2012, 5:06:54 PM5/25/12
to Etsy API V2
Can someone help me?

Thanks.

On May 19, 4:28 pm, David <darkbluefantas...@gmail.com> wrote:
> 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/... tohttp://sandbox.openapi.etsy.com/v2/...,

Jason Wong

unread,
May 25, 2012, 5:12:31 PM5/25/12
to etsy-...@googlegroups.com
Hi David,

Did you change both urls to sandbox.openapi.etsy.com? Also, in order to
pull private data, you need to actually do an oauth request for a token.

http://www.etsy.com/developers/documentation/getting_started/oauth


cheers,
JW
Reply all
Reply to author
Forward
0 new messages