Andrew Newby
Andrew Newby

Reputation: 5206

Way to get item details + images in Etsy API?

I'm not sure if this is the place to ask, but the Etsy developer support is stupidly slow to reply (been waiting 4 days, and that was just to see if I could go ahead with the project - as I didn't want to break their TOS). Anyway, that aside...

I have a script I'm going to offer to our users, that would call the following feed: (using the details here: https://www.etsy.com/developers/documentation/getting_started/requests )

https://openapi.etsy.com/v2/shops/%s/listings/active?method=GET&api_key=$etsy_key&limit=200

That would then get the items they have for sale on their shop. So far, so good. One slight problem... there are no images!!! Now, based on their documentation (https://www.etsy.com/developers/documentation/getting_started/images) it says that you have to do a single request for EVERY item!

https://openapi.etsy.com/v2/listings/ITEM_ID/images/?api_key=xxxx

Surely that can't be right? So we have to do:

There has to be a better way, surely?

I'm all ears to suggestions, as this is driving me nuts.

Upvotes: 5

Views: 4174

Answers (4)

helloJello
helloJello

Reputation: 196

This is the correct answer.

According to the etsy api documentation, you should be able to get the images by adding "includes=Images" to the end of your call.

This will return the listings with all of their images.

Upvotes: 2

CedCommerce
CedCommerce

Reputation: 1

For getting the Item details you can use -- getListing method of the ETSY API and getInventory call for getting variations and other details.

For getting the Images for an item use --- findAllListingImages call of the ETSY API

Upvotes: 0

Mark Hillard
Mark Hillard

Reputation: 212

If you're using (or can use) jQuery, then I'd recommend looping through each listing and displaying them via AJAX. The JSON data that gets returned from an API call looks something like this:

Etsy Data

This is all one big JSON object that includes specific data for each listing, including the image/dimensions, so you need to grab each one individually (see results array).

One way you can do this is with a for loop inside the success callback. You'd then assign variables for each value you want (using dot notation to parse though the JSON) and then build out your HTML using those variables.

$(document).ready(function () {
    // global variables
    var url = 'https://openapi.etsy.com/v2/listings/active.js?includes=MainImage',
        key = '9njigunpqge5htjynd9uu52f',
        limit = 25; // etsy api maximum

    // get data
    $.ajax({
        url: url,
        data: {
            api_key: key,
            limit: limit,
        },
        dataType: 'jsonp',
        success: function (data) {
            // log etsy data
            console.log(data);

            // for each listing... *
            for (var i = 0; i < data.results.length; i++) {
                // * assign listing variables
                var item = data.results[i];
                var url = item.url;
                var image = item.MainImage.url_570xN; // 75x75, 170x135, 570xN, fullxfull
                var title = item.title;
                var price = item.price;
                var quantity = item.quantity;

                // * build html structure for each listing
                var result = $('<div class="item">\
                    <div class="item-image">\
                        <a href="' + url + '"><img src="' + image + '"/></a>\
                    </div>\
                    <div class="item-details">\
                        <p class="item-title">' + title + '</p>\
                        <p class="item-price">$' + price + '</p>\
                        <p class="item-quantity">' + quantity + ' left</p>\
                    </div>\
                </div>');

                // * append listings
                $('#some-element').append(result);
            }
        }
    });
});

The available image sizes from the API are outlined here: https://www.etsy.com/developers/documentation/reference/listingimage.

I recently created a more fully featured Etsy Shop with pagination at http://codepen.io/markhillard/pen/mErRPk if you want to take a look.

Hope this helps.

Upvotes: 3

thesasha
thesasha

Reputation: 81

According to the etsy forums, you should be able to get the images by adding "includes=MainImage" to the end of your call.

Upvotes: 8

Related Questions