timotheus / ebaysdk-python

eBay API SDK for Python
https://developer.ebay.com/tools/sdks
Other
809 stars 326 forks source link

Unable to list item - country code, currency, #383

Closed nubonics closed 11 months ago

nubonics commented 11 months ago

Not sure why it says that the country code and currency are missing, ive included them, been trying to find a solution for a day or so, but no such luck.

from ebaysdk.trading import Connection as Trading
from ebaysdk.exception import ConnectionError

from ListLikeItem import list_item

def verify_add_item(yaml_file, item_details):
    """
    Verify if an item can be listed on eBay.

    Args:
    - yaml_file: Path to the YAML configuration file.
    - item_details: A dictionary containing details of the item to be listed.

    Returns:
    - Response from the eBay API.
    """
    try:
        api = Trading(config_file=yaml_file)  # Change siteid as needed
        response = api.execute('VerifyAddItem', {'Item': item_details})
        return response.dict()

    except ConnectionError as e:
        print(e)
        return e.response.dict()

def live_listing(yaml_file=None, item_details=None):
    response = list_item(yaml_file, item_details)
    if response and 'Ack' in response and response['Ack'] == 'Success' and 'ItemID' in response:
        item_id = response['ItemID']
        item_url = f"https://www.ebay.com/itm/{item_id}"
        print("Item listed successfully. URL:", item_url)
    else:
        print("Item listing failed.")

    return response

if __name__ == '__main__':
    yaml_file = r'C:\Users\nubonix\PycharmProjects\SellingHotwheelsEbay\ebaysdk-python\ebay.yaml'

    item_details = {
        'Title': "Hot Wheels Tropicool Series 2 of 4 Cars Baja Bug White/Red Bug'n Taxi",
        'Description': 'Card may have handling wear, please view photos or feel free to send us a message.',
        'PrimaryCategory': {'CategoryID': '180506'},
        'StartPrice': '7.00',
        'ConditionID': '3000',  # Used in good condition
        'Country': 'US',
        'Currency': 'USD',
        'DispatchTimeMax': '1',
        'ListingDuration': 'GTC',  # Good 'Til Cancelled
        'ListingType': 'FixedPriceItem',
        'PostalCode': '98607',
        'Quantity': '1',
        'ReturnPolicy': {
            'ReturnsAcceptedOption': 'ReturnsAccepted',
            'RefundOption': 'MoneyBack',
            'ReturnsWithinOption': 'Days_30',  # Correct value for the return window
            'ShippingCostPaidByOption': 'Seller'
        },
        'ShippingDetails': {
            'ShippingType': 'Flat',
            'ShippingServiceOptions': {
                'ShippingServicePriority': '1',
                'ShippingService': 'USPSFirstClass',
                'FreeShipping': 'True'
            },
            'ExcludeShipToLocation': ['Alaska/Hawaii', 'US Protectorates', 'APO/FPO']
        },
        'Site': 'US',
        'PictureDetails': {
            'PictureURL': [
                'https://i.ebayimg.com/00/s/MTYwMFgxMjAw/z/zXAAAOSwpdxjm976/$_57.JPG'
            ]
        }
    }

    print(item_details)
    # response = verify_add_item(yaml_file, item_details)
    response = live_listing(yaml_file=yaml_file, item_details=item_details)
    print("Response from list_item:", response)
C:\Users\nubonix\PycharmProjects\SellingHotwheelsEbay\.venv\Scripts\python.exe C:\Users\nubonix\PycharmProjects\SellingHotwheelsEbay\ListItem.py 
{'Title': "Hot Wheels Tropicool Series 2 of 4 Cars Baja Bug White/Red Bug'n Taxi", 'Description': 'Card may have handling wear, please view photos or feel free to send us a message.', 'PrimaryCategory': {'CategoryID': '180506'}, 'StartPrice': '7.00', 'ConditionID': '3000', 'Country': 'US', 'Currency': 'USD', 'DispatchTimeMax': '1', 'ListingDuration': 'GTC', 'ListingType': 'FixedPriceItem', 'PostalCode': '98607', 'Quantity': '1', 'ReturnPolicy': {'ReturnsAcceptedOption': 'ReturnsAccepted', 'RefundOption': 'MoneyBack', 'ReturnsWithinOption': 'Days_30', 'ShippingCostPaidByOption': 'Seller'}, 'ShippingDetails': {'ShippingType': 'Flat', 'ShippingServiceOptions': {'ShippingServicePriority': '1', 'ShippingService': 'USPSFirstClass', 'FreeShipping': 'True'}, 'ExcludeShipToLocation': ['Alaska/Hawaii', 'US Protectorates', 'APO/FPO']}, 'Site': 'US', 'PictureDetails': {'PictureURL': ['https://i.ebayimg.com/00/s/MTYwMFgxMjAw/z/zXAAAOSwpdxjm976/$_57.JPG']}}
'AddItem: Class: RequestError, Severity: Error, Code: 10009, No <Item.Currency> exists or <Item.Currency> is specified as an empty tag. No <Item.Currency> exists or <Item.Currency> is specified as an empty tag in the request., Class: RequestError, Severity: Error, Code: 10009, No <Item.Country> exists or <Item.Country> is specified as an empty tag. No <Item.Country> exists or <Item.Country> is specified as an empty tag in the request., Class: RequestError, Severity: Error, Code: 10009, No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag. No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag in the request.'
Item listing failed.
Response from list_item: {'Timestamp': '2023-12-31T04:37:35.424Z', 'Ack': 'Failure', 'Errors': [{'ShortMessage': 'No <Item.Currency> exists or <Item.Currency> is specified as an empty tag.', 'LongMessage': 'No <Item.Currency> exists or <Item.Currency> is specified as an empty tag in the request.', 'ErrorCode': '10009', 'SeverityCode': 'Error', 'ErrorParameters': {'Value': 'Item.Currency', '_ParamID': '0'}, 'ErrorClassification': 'RequestError'}, {'ShortMessage': 'No <Item.Country> exists or <Item.Country> is specified as an empty tag.', 'LongMessage': 'No <Item.Country> exists or <Item.Country> is specified as an empty tag in the request.', 'ErrorCode': '10009', 'SeverityCode': 'Error', 'ErrorParameters': {'Value': 'Item.Country', '_ParamID': '0'}, 'ErrorClassification': 'RequestError'}, {'ShortMessage': 'No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag.', 'LongMessage': 'No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag in the request.', 'ErrorCode': '10009', 'SeverityCode': 'Error', 'ErrorParameters': {'Value': 'Item.ListingDuration', '_ParamID': '0'}, 'ErrorClassification': 'RequestError'}], 'Version': '1341', 'Build': 'E1341_UNI_API5_19110890_R1'}

Process finished with exit code 0
nubonics commented 11 months ago

Heres a temp hotfix though

def list_item(yaml_file, item_details):
    try:
        api = Trading(config_file=yaml_file, siteid='0')

        # Hardcoding values for testing
        hardcoded_item_details = item_details.copy()  # Make a copy of item_details
        hardcoded_item_details['Currency'] = 'USD'  # Hardcoded currency
        hardcoded_item_details['Country'] = 'US'    # Hardcoded country
        hardcoded_item_details['ListingDuration'] = 'GTC'  # Hardcoded listing duration

        response = api.execute('AddItem', {'Item': hardcoded_item_details})
        return response.dict()

    except ConnectionError as e:
        print(e)
        return e.response.dict()