anitabyte / etsyv3

Python client for the Etsy OpenAPI v3
GNU General Public License v3.0
58 stars 24 forks source link

Enhancement: Future implementation #2

Closed yuliyan-valchev-ft closed 1 year ago

yuliyan-valchev-ft commented 1 year ago

Hello,

First of all thank you for writing this and making it available, it looks great. I just wanted to ask if you plan on adding implementation for some of the endpoints which maybe became available since your last commit. I am mostly wondering about those two https://developer.etsy.com/documentation/reference#operation/updateListing Patch https://developer.etsy.com/documentation/reference#operation/uploadListingImage

According to the documentation they are ready for production use.

d-winch commented 1 year ago

I was looking for the same.

I'm able to update listings using the following: https://github.com/d-winch/etsyv3/tree/update-listing

I haven't tried Listing Images yet.

muratali016 commented 1 year ago

I was looking for the same.

I'm able to update listings using the following: https://github.com/d-winch/etsyv3/tree/update-listing

I haven't tried Listing Images yet.

what are you passing for listing: parameter? @d-winch

d-winch commented 1 year ago

@muratali016

Create an UpdateListingRequest from listing_request.py and pass that object.

You may want to introduce this nullable fix first.

Otherwise, all nullable fields seem to be set to None. I believe this is the same issue mentioned in anitabyte/etsyv3#4.

muratali016 commented 1 year ago

How were you able to update the listing that would be amazing if you could provide an example of your usage. I have to change a price of particular item @d-winch

d-winch commented 1 year ago

@muratali016

Updating price(s) is done via updateListingInventory.

You need to create your Product list with offerings, which depends on your use case. This can become more complex with variation listings with multiple SKUs, prices, quantities, properties, etc.

Here's a brief example to update the price on a single item listing.

products = [Product(sku=None, property_values=[], offerings=[{"price": "99.99", "quantity": 10, "is_enabled": True}])]

listing_inventory = UpdateListingInventoryRequest(products=products, price_on_property=None, 
quantity_on_property=None, sku_on_property=None)

etsy.update_listing_inventory(listing_id=listing_id, listing_inventory=listing_inventory)
{'products': [{'product_id': 16228077711, 'sku': '', 'is_deleted': False, 'offerings': [{'offering_id': 16181080511, 'quantity': 10, 'is_enabled': True, 'is_deleted': False, 'price': {'amount': 9999, 'divisor': 100, 'currency_code': 'GBP'}}], 'property_values': []}], 'price_on_property': [], 'quantity_on_property': [], 'sku_on_property': []}

I would recommend using getListingInventory and creating the request from the response.

E.g.,

req = etsy.get_listing_inventory(listing_id=1111111111)

listing_inventory_request = UpdateListingInventoryRequest.generate_request_from_inventory_response(req)

listing_inventory_request.products[0].__dict__
{'sku': 'XXXXXX', 'property_values': [{'property_id': 62809790533, 'property_name': 'Size', 'scale_id': 51, 'value_ids': [87994062720], 'values': ['S']}], 'offerings': [{'quantity': 100, 'is_enabled': True, 'price': 24.99}]}

listing_inventory_request.products[0].offerings[0]["price"]
24.99

Make your changes to the prices and submit them using update_listing_inventory.

muratali016 commented 1 year ago

Thanks a lot @d-winch

d-winch commented 1 year ago

Hello,

First of all thank you for writing this and making it available, it looks great. I just wanted to ask if you plan on adding implementation for some of the endpoints which maybe became available since your last commit. I am mostly wondering about those two https://developer.etsy.com/documentation/reference#operation/updateListing Patch https://developer.etsy.com/documentation/reference#operation/uploadListingImage

According to the documentation they are ready for production use.

@yuliyan-valchev-ft

I've implemented both endpoints and have been using them with our own listings. Due to time constraints, I have not yet implemented tests for them so please be careful.

Update Listing: https://github.com/anitabyte/etsyv3/pull/6

Upload Listing Image: https://github.com/anitabyte/etsyv3/pull/8

Be wary of the issue with nulled fields: https://github.com/anitabyte/etsyv3/pull/5

anitabyte commented 1 year ago

Apologies, this seems like it's been a really fruitful thread and I've not been able to keep up with it due to GitHub deciding to not notify me, helpfully. I'll get on some of this as and when I have time.

muratali016 commented 1 year ago

@d-winch @anitabyte When I use this:

req = etsy.get_listing_inventory(listing_id=1111111111)

listing_inventory_request = UpdateListingInventoryRequest.generate_request_from_inventory_response(req)

listing_inventory_request.products[0].__dict__
{'sku': 'XXXXXX', 'property_values': [{'property_id': 62809790533, 'property_name': 'Size', 'scale_id': 51, 'value_ids': [87994062720], 'values': ['S']}], 'offerings': [{'quantity': 100, 'is_enabled': True, 'price': 24.99}]}

listing_inventory_request.products[0].offerings[0]["price"]
24.99

sometimes doesn't work especially on products that have multiple SKUs

Update: Got this:

for product in listing_inventory_request.products:
    for offering in product.offerings:
        offering["price"] = 79.9
d-winch commented 1 year ago

@muratali016

The above was just a simple example. It will depend on your specific listings.

Could you open a new issue and give your specific code snippet and error?

yuliyan-valchev-ft commented 1 year ago

I see that all the PRs have been merged now by @anitabyte. I will close this specific issue since my initial question has been handled, many thanks to @d-winch for the help! 👍 🚀