Andrew Hall
Andrew Hall

Reputation: 3073

Etsy PHP API - Delivery Options

Using the Etsy Listing API, i have listings returned that match a keyword and I can paginate through them no problems.

However, I want to find only listings that deliver to the UK.

I have tried to use the region URL parameter, but i still get items that can only be delivered to the USA.

Can someone help me to understand what I need to pass in order to get UK shippable items please?

Upvotes: 4

Views: 763

Answers (2)

Manoj K
Manoj K

Reputation: 477

Here is the code to get listing that ships/deliver to "United Kingdom"

<?php
$apiContent = file_get_contents("https://openapi.etsy.com/v2/listings/active?api_key=YOUR-API-KEY-HERE&includes=ShippingInfo(destination_country_name)");
        $contentDecode = json_decode($apiContent, true);
        $total=0;
        foreach ($contentDecode['results'] as $row) {
            if (isset($row['ShippingInfo'])) {
                foreach ($row['ShippingInfo'] as $r) {
                    if ($r['destination_country_name'] == "United Kingdom") {
                        echo "<pre>";
                        print_r($row);
                        $total++;
                    }
                }
            }
        }
        echo $total;
?>

I used includes=ShippingInfo(destination_country_name) parameter to get the shipping details of the listing. It get the in which country listing will be delivered. Hope it will work for you.

Upvotes: 1

pabl0rg
pabl0rg

Reputation: 171

If you want to use only listings that can ship to UK, you have to look at the listsing's ShippingInfo. Here's how I did it:

$json = file_get_contents("https://openapi.etsy.com/v2/listings/active?keywords=ISBN&region=GB&includes=ShippingInfo(destination_country_id)&api_key=");
$listings = json_decode($json, true);
foreach($listings['results'] as $listing) {
    if (isset($listing['ShippingInfo'])) {
        foreach ($listing['ShippingInfo'] as $shipping) {
            if ($shipping['destination_country_id'] == 105) {
                //this listing ships to UK
                print_r($listing);
            }       
        }

    }
}

Upvotes: 2

Related Questions