How to get sold items with API?

778 views
Skip to first unread message

Jen Beaven

unread,
Dec 21, 2011, 4:14:37 PM12/21/11
to etsy-...@googlegroups.com
My client would like to be able to display sold items (on their website, not yours) so customers can request "one like this one." 

I can't see how to do this via the API. If I'm reading it right, I'd have to use oauth to log in to their account to read inactive listings, which would mean anyone browsing their site would have to be able to log in to their account to see inactive listings. 

Really rather not scrape the "sold" screen. Is there any other way?

david olick

unread,
Dec 21, 2011, 4:38:32 PM12/21/11
to etsy-...@googlegroups.com
If you can run scripts on your server, you could load the data dynamically via a GET request.  Jquery makes it quite simple.  Also you could load it statically with the page where all the API calls are done outside of the html page... but this may lead to a "slower" feeling to the page load.

If you can't run scripts on your server... well, I'm not sure how you could securely handle this.  You are not supposed to use any private tokens out in public html, including the private API key Etsy gave you.

--
You received this message because you are subscribed to the Google Groups "Etsy API V2" group.
To view this discussion on the web visit https://groups.google.com/d/msg/etsy-api-v2/-/L0dBZqESDhIJ.
To post to this group, send email to etsy-...@googlegroups.com.
To unsubscribe from this group, send email to etsy-api-v2...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/etsy-api-v2?hl=en.



--
David Olick
CTO
Oriku Inc.

Katrina Owen

unread,
Dec 21, 2011, 5:06:11 PM12/21/11
to etsy-...@googlegroups.com
On Wed, Dec 21, 2011 at 10:14 PM, Jen Beaven <jen.b...@gmail.com> wrote:
> My client would like to be able to display sold items (on their website, not
> yours) so customers can request "one like this one."

Yepp, you can do this. It does require authentication via oauth like
you suspected. There are a few ways you could go about this, but I
think the easiest would be to go via the Transaction resource:

http://www.etsy.com/developers/documentation/reference/transaction
The transaction has the associated listing.

If you get help constructing the query just holler.

Katrina

Jen Beaven

unread,
Dec 21, 2011, 5:43:00 PM12/21/11
to etsy-...@googlegroups.com
Definitely need help. I have't done any oauth yet. It does seem like anyone who wants to browse the site would have to log in as the user that owns the items. 

Even if they had to log i with their own etsy id, that would be a show stopper; we want people who have never been to etsy to be able to request an item like one of the sold ones, and having to make an etsy id would be too high a barrier.

Katrina Owen

unread,
Dec 21, 2011, 5:48:11 PM12/21/11
to etsy-...@googlegroups.com
On Wed, Dec 21, 2011 at 11:43 PM, Jen Beaven <jen.b...@gmail.com> wrote:
> Definitely need help. I have't done any oauth yet. It does seem like anyone
> who wants to browse the site would have to log in as the user that owns the
> items.

Ah, that's not quite how it works. Basically, only your customer needs
to log in, and just once: that way you get the oauth credentials for
the shop, and you can make the requests to the API as that person.

Since you only need to do this for a single person, you don't need to
code up the whole oauth dance in the website, you could just have a
script that does it once.

Once you have the oauth secret and token, then you would build up the
request (it would be the same every time, but you might have to loop
through to grab all the items).

What language are you working in?

Jen Beaven

unread,
Dec 21, 2011, 7:42:31 PM12/21/11
to etsy-...@googlegroups.com
Ohhhh  (*light dawns*) that's much easier.

I'm writing in php and using the google code oauth-php library ( http://code.google.com/p/oauth-php/ )

So far I've managed to get a login url and use it to login and get a verfication code. Now to figure out what to do with that :-)

Katrina Owen

unread,
Dec 22, 2011, 2:53:41 AM12/22/11
to etsy-...@googlegroups.com
On Thu, Dec 22, 2011 at 1:42 AM, Jen Beaven <jen.b...@gmail.com> wrote:

> I'm writing in php and using the google code oauth-php library
> ( http://code.google.com/p/oauth-php/ )

> So far I've managed to get a login url and use it to login and get a
> verfication code. Now to figure out what to do with that :-)

Here, try this:

https://gist.github.com/898932

I used a different oauth library, but you've already gotten the oauth
part working, so I bet you know which bits to swap out!

Jen Beaven

unread,
Dec 27, 2011, 12:10:11 PM12/27/11
to etsy-...@googlegroups.com
Thanks, that was very helpful. 

If using the google code oauth-php library, when requesting the first token, you have to pass in scope and the callback url:

$token = OAuthRequester::requestRequestToken($consumer_key, $user_id,  
array('scope' => "email_r listings_r transactions_r",'oauth_callback' => $callback_url));

And in the actual "authorize" url that you redirect to, use the "out of band" syntax:
$uri .= 'oauth_token='.rawurlencode($token['token']) ."&oauth_callback='oob'";



Katrina Owen

unread,
Dec 27, 2011, 6:20:42 PM12/27/11
to etsy-...@googlegroups.com
On Tue, Dec 27, 2011 at 6:10 PM, Jen Beaven <jen.b...@gmail.com> wrote:
> If using the google code oauth-php library, when requesting the first token,
> you have to pass in scope and the callback url:

Ah, good to know. I'm updating the github gist with that info.
Thanks!

Katrina

Jen Beaven

unread,
Dec 28, 2011, 12:17:45 PM12/28/11
to etsy-...@googlegroups.com
Yay it all works!

In case anyone wants to see the result:

(I can only take credit for the code; graphic design by my bro-in-law.)
Reply all
Reply to author
Forward
0 new messages