Search code examples
phpapietsy

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?


Solution

  • 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);
                }       
            }
    
        }
    }