简体   繁体   中英

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?

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

    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM