XeroAPI/xero-python

getItem with / in Item Code

weyersma opened this issue · 0 comments

Hi, I use getItem to check if an item exists in Xero. If the item does not exist I use a createItem to create it. The Item Code has a / in it. Using getItem it returns an error when searching for the item so I assume the item does not exist. When I then add the createItem it returns that the item does exist. Could you advise how I can check if the item exists if the item code contains a /

My code snippet:

try:
    print(itemCode)
    items = accounting_api.get_item(xero_tenant_id, itemCode)

    return 'exists'
except Exception as e:
    if hasattr(e, 'message'):
        print(e.message)
    else:
        print(e)
    #print(jsonify(getexception))
    newItem = {}

    newJSON = '{'
    newJSON = newJSON + '"Code": "' + str((itemCode)) + '", '
    newJSON = newJSON + '"Name": "' + str(itemDescription) + '", '
    newJSON = newJSON + '"Description": "' + str(itemDescription) + '", '
    newJSON = newJSON + '"PurchaseDescription": "' + str(itemDescription) + '", '
    newJSON = newJSON + '"SalesDetails": { "UnitPrice": "' + str(price) + '", "AccountCode": "' + str(accountCode) + '", "TaxType": "' + str(taxType) + '"} '
    newJSON = newJSON + '}'
    print (newJSON)
    my_json_string = json.loads(newJSON)
    try:
        payments = accounting_api.create_items(
            xero_tenant_id, my_json_string
        )
        return "created"
    except AccountingBadRequestException as exception: