anitabyte / etsyv3

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

raise NotImplementedError update_listing() #16

Closed pascale64 closed 1 year ago

pascale64 commented 1 year ago

Hi, I keep getting this error, I am passing my id and listing_id, but unsure how to pass "UpdateListingRequest" parametre, do I need to pass the complete list, even if I only want to update one item, how do I pass the list? The UpdateListingRequest seems to show fields are optional? I have tried multiple ways, lists, dict, json.dumps etc, but I am lost with passing this UpdateListingRequest. This works: BDF_Etsy.get_listing(985775823, 151661511) but, this does not body={'title': 'Vintage French table lamp in quality bronze with a handmade lampshade of your best choice'} BDF_Etsy.update_listing(985775823, 1585777523, body) I understand this is not an issue with your code, which is great by the way, but i am stuck! Warm regards Paul

pascale64 commented 1 year ago

Hi, I have research why I have the origional error, I Had used pip3 top install the package afte a system update but I had an old version, so now I have version 0.0.6, I am getting a new error, I believe this is still because I am not sending the UpdateListingRequest incorrectly, I am sending ihe list as a dictonary; body={'image_ids':[], 'title': 'Vintage French table lamp in quality bronze with a handmade lampshade of your choice', 'description': 'A stunning vintage French table lamp for your home. brocante\n\n\nMerci de votre visite -Thanks for your visit!\n\nNUMERO TARIFAIRE69091900B\nPOIDS1.8KGBY23/10/11McoTRC', 'materials': ['Bronze', 'Fabric', 'Lampshade polyphane', 'Metal rings'], 'should_auto_renew': True, 'shipping_profile_id': 55880902836, 'shop_section_id': 20081659, 'item_weight': 0.0, 'item_length': 0.0, 'item_width': 0.0, 'item_height': 0.0, 'item_weight_unit': 'g', 'item_dimensions_unit': 'mm', 'is_taxable': True, 'taxonomy_id': 2815, 'tags': ['table lamp', 'handmade lampshade', 'country home', 'farmhouse decor', 'classic decor', 'rococo', 'living room', 'toile de Jouy', 'French toile', 'signed bronze', 'blue and gold', 'acanthus', 'chateau decor'], 'who_made': 'someone_else', 'when_made': '1930s', 'featured_rank': 0, 'is_personalizable': False, 'personalization_is_required': False, 'personalization_char_count_max': False, 'personalization_instructions': False, 'state': 'inactive', 'is_supply': False, 'production_partner_ids': [], 'listing_type': 'physical'} to bdf_update=BDF_Etsy.update_listing(985775823, 1585777523, body) I am now getting Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.9/dist-packages/etsyv3/etsy_api.py", line 340, in update_listing return self._issue_request(uri, method=Method.PATCH, request_payload=listing) File "/usr/local/lib/python3.9/dist-packages/etsyv3/etsy_api.py", line 162, in _issue_request raise Exception() All help is greatly needed. Warm regards Paul

pascale64 commented 1 year ago

Hi, I have decided to test what comes out of the UpdateListingRequest(Request), so I found that no ater how I tried to nut the data, List, Dict, String etc all of the items where grouped together as part of the first item "image_id" as follows body={"image_ids":[], "title": "Vintage French table lamp in quality bronze with a handmade lampshade of your choice", "description": "A stunning vintage French table lamp for your home. brocante\n\n\nMerci de votre visite -Thanks for your visit!\n\nNUMERO TARIFAIRE69091900B\nPOIDS1.8KGBY23/10/11McoTRC", "materials": ["Bronze", "Fabric", "Lampshade polyphane", "Metal rings"], "should_auto_renew": True, "shipping_profile_id": 55880902836, "shop_section_id": 20081659, "item_weight": "", "item_length": "", "item_width": "", "item_height": "", "item_weight_unit": "g", "item_dimensions_unit": "mm", "is_taxable": True, "taxonomy_id": 2815, "tags": ["table lamp", "handmade lampshade", "country home", "farmhouse decor", "classic decor", "rococo", "living room", "toile de Jouy", "French toile", "signed bronze", "blue and gold", "acanthus", "chateau decor"], "who_made": "someone_else", "when_made": "1930s", "featured_rank": 0, "is_personalizable": False, "personalization_char_count_max": False, "personalization_instructions": False, "state": "active", "is_supply": False, "production_partner_ids": [], "listing_type": "physical"} returned ;

"personalization_is_required": False,'{"image_ids": {"image_ids": [], "title": "Vintage French table lamp in quality bronze with a handmade lampshade of your choice", "description": "A stunning vintage French table lamp for your home. brocante\n\n\nMerci de votre visite -Thanks for your visit!\n\nNUMERO TARIFAIRE69091900B\nPOIDS1.8KGBY23/10/11McoTRC", "materials": ["Bronze", "Fabric", "Lampshade polyphane", "Metal rings"], "should_auto_renew": true, "shipping_profile_id": 55880902836, "shop_section_id": 20081659, "item_weight": "", "item_length": "", "item_width": "", "item_height": "", "item_weight_unit": "g", "item_dimensions_unit": "mm", "is_taxable": true, "taxonomy_id": 2815, "tags": ["table lamp", "handmade lampshade", "country home", "farmhouse decor", "classic decor", "rococo", "living room", "toile de Jouy", "French toile", "signed bronze", "blue and gold", "acanthus", "chateau decor"], "who_made": "someone_else", "when_made": "1930s", "featured_rank": 0, "is_personalizable": false, "personalization_is_required": false, "personalization_char_count_max": false, "personalization_instructions": false, "state": "active", "is_supply": false, "production_partner_ids": [], "listing_type": "physical"}, "title": null, "description": null, "materials": null, "should_auto_renew": null, "shipping_profile_id": null, "shop_section_id": null, "item_weight": null, "item_length": null, "item_width": null, "item_height": null, "item_weight_unit": null, "item_dimensions_unit": null, "is_taxable": null, "taxonomy_id": null, "tags": null, "who_made": null, "when_made": null, "featured_rank": null, "is_personalizable": null, "personalization_is_required": null, "personalization_char_count_max": null, "personalization_instructions": null, "state": null, "is_supply": null, "production_partner_ids": null, "listing_type": null, "_nullable": ["materials", "shipping_profile_id", "shop_section_id", "item_weight", "item_length", "item_width", "item_height", "item_weight_unit", "item_dimensions_unit", "tags", "featured_rank", "production_partner_ids", "type"], "_mandatory": []}' so I tried the simpliest body = [], "hello"

body = ([], "hello") r = UpdateListingRequest(body) r= json.dumps(r.dict) r '{"image_ids": [[], "hello"], "title": null, "description": null, "materials": null, "should_auto_renew": null, "shipping_profile_id": null, "shop_section_id": null, "item_weight": null, "item_length": null, "item_width": null, "item_height": null, "item_weight_unit": null, "item_dimensions_unit": null, "is_taxable": null, "taxonomy_id": null, "tags": null, "who_made": null, "when_made": null, "featured_rank": null, "is_personalizable": null, "personalization_is_required": null, "personalization_char_count_max": null, "personalization_instructions": null, "state": null, "is_supply": null, "production_partner_ids": null, "listing_type": null, "_nullable": ["materials", "shipping_profile_id", "shop_section_id", "item_weight", "item_length", "item_width", "item_height", "item_weight_unit", "item_dimensions_unit", "tags", "featured_rank", "production_partner_ids", "type"], "_mandatory": []}'

I am at a complete loss Please Help! Warm regards Paul

anitabyte commented 1 year ago

Hi Paul,

You shouldn't be able to create an UpdateListingRequest like that - it should raise an exception. I'll double check that - I might have removed the code that handled that by accident.

If you try to create the UpdateListingRequest like this (eg):

r = UpdateListingRequest(title="New title", description="Description")

or

body = {title: "New Title", description: "Description"}
r = UpdateListingRequest(**body)

You might have better luck.

pascale64 commented 1 year ago

Hi Anitabyte Thank you for getting back to me, what I really want to know is what do I pass to "update_listing", as the part "listing", I have tried dictionaries list and tuples, but I get the same error, I have tried ; body={ "title": "Vintage French table lamp in quality bronze with a handmade lampshade of your choice", }

bdf_update=BDF_Etsy.update_listing(985775823, 1585777523, **body) TypeError: update_listing() got an unexpected keyword argument 'title' bdf_update=BDF_Etsy.update_listing(985775823, 1585777523,title="Vintage French table lamp in quality bronze with a handmade lampshade of your choice",listing_type= "physical") but I get the same error. TypeError: update_listing() got an unexpected keyword argument 'title' I have read the For POST and PUT requests (requests that need payloads), there are subclassed Request types for each type. They generally take all required arguments into a constructor that is then serialised into JSON when passed to an API-calling method. Where you wish to null an optional parameter in a call, you should create the request parameter with the empty-form of whatever you're trying to null, so if the API takes a string, provide ""; if a list, []. but I dont understand how to construct this pay load. This is a project for me, I sell on Ebay and Etsy, so when an item sells on one site I can deactivate it on the other, I could just delete the listing, but this will not help me understand how to construct a payload. my code for finances and sales works great as I dont need to pass a payload Thank you for your help and code Warm regards Paul

d-winch commented 1 year ago

Hi Anitabyte Thank you for getting back to me, what I really want to know is what do I pass to "update_listing", as the part "listing", I have tried dictionaries list and tuples, but I get the same error, I have tried ; body={ "title": "Vintage French table lamp in quality bronze with a handmade lampshade of your choice", }

bdf_update=BDF_Etsy.update_listing(985775823, 1585777523, **body) TypeError: update_listing() got an unexpected keyword argument 'title' bdf_update=BDF_Etsy.update_listing(985775823, 1585777523,title="Vintage French table lamp in quality bronze with a handmade lampshade of your choice",listing_type= "physical") but I get the same error. TypeError: update_listing() got an unexpected keyword argument 'title' I have read the For POST and PUT requests (requests that need payloads), there are subclassed Request types for each type. They generally take all required arguments into a constructor that is then serialised into JSON when passed to an API-calling method. Where you wish to null an optional parameter in a call, you should create the request parameter with the empty-form of whatever you're trying to null, so if the API takes a string, provide ""; if a list, []. but I dont understand how to construct this pay load. This is a project for me, I sell on Ebay and Etsy, so when an item sells on one site I can deactivate it on the other, I could just delete the listing, but this will not help me understand how to construct a payload. my code for finances and sales works great as I dont need to pass a payload Thank you for your help and code Warm regards Paul

You need to provide the update_listing method with a type of UpdateListingRequest, rather than dict, tuple, etc.

You can create one by first importing the UpdateListingRequest from etsyv3/models/listing_request.py and then passing your arguments.

E.g.,

req = UpdateListingRequest(
        title = "Test Title"
        description = "Test Description"
        materials = "Cotton"
        ...
        listing_type = ListingType.PHYSICAL
)

Then pass the UpdateListingRequest variable. update_listing(shop_id=985775823, listing_id=1585777523, listing=req)

If you have your details in a body dict, as anitabyte showed, you should be able to unpack the dict as the input req = UpdateListingRequest(**body)

Or even update_listing(shop_id=985775823, listing_id=1585777523, listing=UpdateListingRequest(**body))

pascale64 commented 1 year ago

Hi David Thank you so much for your help, I am making great progress and understanding more, I am now getting an error File "/usr/local/lib/python3.9/dist-packages/etsyv3/etsy_api.py", line 340, in update_listing return self._issue_request(uri, method=Method.PATCH, request_payload=listing) File "/usr/local/lib/python3.9/dist-packages/etsyv3/etsy_api.py", line 164, in _issue_request raise BadRequest(return_val.json()) etsyv3.etsy_api.BadRequest: {'error': 'Invalid value (null) for boolean'} I am passing a reduced list as body, it includes all the items marked as booleans, this is what results from; req = UpdateListingRequest(body) req.dict {'image_ids': [], 'title': 'test ', 'description': 'A stunning ', 'materials': None, 'should_auto_renew': True, 'shipping_profile_id': None, 'shop_section_id': None, 'item_weight': None, 'item_length': None, 'item_width': None, 'item_height': None, 'item_weight_unit': None, 'item_dimensions_unit': None, 'is_taxable': True, 'taxonomy_id': 2815, 'tags': None, 'who_made': 'someone_else', 'when_made': '1930s', 'featured_rank': None, 'is_personalizable': False, 'personalization_is_required': False, 'personalization_char_count_max': 0, 'personalization_instructions': '', 'state': 'active', 'is_supply': False**, 'production_partner_ids': None, 'listing_type': None, '_nullable': ['materials', 'shipping_profile_id', 'shop_section_id', 'item_weight', 'item_length', 'item_width', 'item_height', 'item_weight_unit', 'item_dimensions_unit', 'tags', 'featured_rank', 'production_partner_ids', 'type'], '_mandatory': []} I am not sure where I am going wrong, Thanks for your help Warm regards Paul

d-winch commented 1 year ago

@pascale64 Could you provide the full code including where you set the body variable?

You can put three backticks (`) before and after your code to format it nicely.

pascale64 commented 1 year ago

Thank you for getting back to me,here is my code from etsyv3 import EtsyAPI from etsyv3.models import Request, UpdateListingRequest BDF_Etsy = EtsyAPI( keystring = bdfapi.keystring, token = bdfapi.access_token, refresh_token = bdfapi.refresh_token, expiry = bdfapi.expires_at )

body={"image_ids":[], "title": "test Vintage French table lamp in quality bronze with a handmade lampshade of your choice", "description": "A stunning vintage French table lamp for your home. brocante\n\n\nMerci de votre visite -Thanks for your visit!\n\nNUMERO TARIFAIRE69091900B\nPOIDS1.8KGBY23/10/11McoTRC", "should_auto_renew": True, "is_taxable": True, "taxonomy_id": 2815, "who_made": "someone_else", "when_made": "1930s", "is_personalizable": False, "personalization_is_required": False, "personalization_char_count_max": 0, "personalization_instructions": "", "state": "active", "is_supply": False,}

BDF_Etsy.update_listing(shop_id=985775823, listing_id=1585777523, listing=UpdateListingRequest(body)) this is where I get the "boolean "erreur", so I then tried this; reg = BDF_Etsy.UpdateListingRequest(body) reg.dict and got this; 'image_ids': [], 'title': 'test ', 'description': 'A stunning ', 'materials': None, 'should_auto_renew': True, 'shipping_profile_id': None, 'shop_section_id': None, 'item_weight': None, 'item_length': None, 'item_width': None, 'item_height': None, 'item_weight_unit': None, 'item_dimensions_unit': None, 'is_taxable': True, 'taxonomy_id': 2815, 'tags': None, 'who_made': 'someone_else', 'when_made': '1930s', 'featured_rank': None, 'is_personalizable': False, 'personalization_is_required': False, 'personalization_char_count_max': 0, 'personalization_instructions': '', 'state': 'active', 'is_supply': False, 'production_partner_ids': None, 'listing_type': None, '_nullable': ['materials', 'shipping_profile_id', 'shop_section_id', 'item_weight', 'item_length', 'item_width', 'item_height', 'item_weight_unit', 'item_dimensions_unit', 'tags', 'featured_rank', 'production_partner_ids', 'type'], '_mandatory': []} when I look at the class UpdateListingRequest in models I see that only the following are booleans; should_auto_renew:, is_taxable:,is_personalizable:personalization_is_required:,is_supply: which I have made True or False, I have left out the items that are nullable, I also tried 1 or 0 instead of Hope this helps. Warm regards Paul

pascale64 commented 1 year ago

David and Anitabyte, I have resolved the issue, all items in the body dict must be strings; ie a boolean must be "True" or "False", and integers must be strings as well"12345", this why I was getting the boolean erreur message, and atleast one image_id must be sent aswell as image_ids:["123456"], or you get an erreur aswell, I hope this helps anybody following me, as this is an excellent piece of code, now I can run Ebay and Etsy shops at the same time not having to worry about selling the same product over night whilst I sleep! Many thanks again Warm regards Paul

d-winch commented 1 year ago

I'm under the belief that the bools get converted to strings but don't have time to check at the moment. If passing a string works then that's great.

I would only pass the data you need to update. So if there are no image_ids to update, don't include it in your body.