Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save objects to xero. #103

Closed
asavpatel opened this issue Oct 9, 2015 · 13 comments
Closed

Can't save objects to xero. #103

asavpatel opened this issue Oct 9, 2015 · 13 comments

Comments

@asavpatel
Copy link
Contributor

I try to do this

contacts = xero_client.contacts.all()
for contact in contacts:
    if contact.get("Name") == supplier_name:
        contact["Addresses"][0]["City"] = "Manhattan"
        xero_client.contacts.save(contact)

# HERE I am trying to mark the invoice as paid.
invoices = xero_client.invoices.get(invoice_number)
for invoice in invoices:
    if invoice.get("Contact").get("Name") == supplier_name:
        invoice["Status"] = "PAID"
        xero_client.invoices.save(invoice)        

but it's throwing this error in both cases.

  xero_client.contacts.save(contact)
  File "/Library/Python/2.7/site-packages/xero/manager.py", line 187, in wrapper
    raise XeroBadRequest(response)
  File "/Library/Python/2.7/site-packages/xero/exceptions.py", line 24, in __init__
    for elem in data['Elements']
    KeyError: 'Elements'

can someone please help me solve this.

@asavpatel
Copy link
Contributor Author

btw Library is generating following XML and it seems it's not correct:

<?xml version="1.0" encoding="UTF-8"?>
<Contact>
   <Addresses>
      <City>Manhattan</City>
   </Addresses>
   <HasAttachments>false</HasAttachments>
   <Phones>
      <PhoneAreaCode />
      <PhoneNumber />
      <PhoneType>DDI</PhoneType>
      <PhoneCountryCode />
      <PhoneAreaCode />
      <PhoneNumber />
      <PhoneType>DEFAULT</PhoneType>
      <PhoneCountryCode />
      <PhoneAreaCode />
      <PhoneNumber />
      <PhoneType>FAX</PhoneType>
      <PhoneCountryCode />
      <PhoneAreaCode />
      <PhoneNumber />
      <PhoneType>MOBILE</PhoneType>
      <PhoneCountryCode />
   </Phones>
   <IsSupplier>true</IsSupplier>
   <ContactGroups />
   <BankAccountDetails />
   <ContactID>06f98f7c-7878-4472-bbed-7811bf3dcb54</ContactID>
   <HasValidationErrors>False</HasValidationErrors>
   <EmailAddress />
   <ContactPersons />
   <IsCustomer>false</IsCustomer>
   <ContactStatus>ACTIVE</ContactStatus>
   <Name>asav supplier</Name>
</Contact>

@MJMortimer
Copy link
Contributor

Hi @aidanlister,

I've just tried to replicate this issue and found that the same thing is hapening for me on the latest master. We have an open community thread disscusion here for reference https://community.xero.com/developer/discussion/12184472.

Has the serialization process been changed lately that could cause the serializtion to be incorrect?

Cheers,
Matt

@aidanlister
Copy link
Collaborator

No intentional changes ... I'll do some bisection and get back to you.

@aidanlister
Copy link
Collaborator

I added some tests to pick up on the problem:
2ef0ce4

@aidanlister
Copy link
Collaborator

There was a PR which fixed this, which is now merged in.

MJMortimer added a commit to MJMortimer/pyxero that referenced this issue Oct 11, 2015
Relates to freakboy3742#103 and https://community.xero.com/developer/discussion/12184472

If you get a contact (and probably other things), edit the dict and send it straight back, the Xero API will throw a bad request exception with the message "PostDataInvalidException: The element 'HasValidationErrors' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name."
@MJMortimer
Copy link
Contributor

@aidanlister, I've opened one last PR to help resolve Asav's issue. The PR will also help others tryig to use the Library i the same fashion.

PR #105

@asavpatel
Copy link
Contributor Author

Thanks guys for all the help.
last fix solved my contacts.save() problem.
but now when I try to save invoice info the same way. I am getting this error.

PostDataInvalidException: The element 'IsDiscounted' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.: 

@asavpatel
Copy link
Contributor Author

Adding the following fields into NO_SEND_FEILDS fixed my issue.
I don't know if it's a correct way of solving this or not.

'IsDiscounted',
'DateString',
'HasErrors',
'DueDateString',

Please advise.

@aidanlister
Copy link
Collaborator

I wonder if something has changed on Xero's end to be more strict? I'll add these too.

@nadzimo
Copy link

nadzimo commented Oct 29, 2017

Also getting a similar error when trying to update an invoice:

PostDataInvalidException: The element 'HasAccount' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.:

Any update on that old issue?

@peircej
Copy link
Contributor

peircej commented Apr 4, 2020

I had same error as @nadzimo and similar solution to previous. When I add "HasAccount" to the pyxero.basemanager.BaseManager.NO_SEND_FIELDS, that PostDataInvalidException goes away

@aidanlister
Copy link
Collaborator

If someone makes a PR I'll merge it

peircej added a commit to peircej/pyxero that referenced this issue Apr 6, 2020
It seems xero has a new field in invoices called HasAccount but doesn't
want this to be uploaded in the API? Don't send when saving changes.

see issue freakboy3742GH-103
@peircej
Copy link
Contributor

peircej commented Apr 6, 2020

There's actually a further issue with (at least one of) the date fields because when the above issue was fixed the API then complained about the date being in the wrong format. Re-saving the datetime to a simple date (in my script not in pyxero) fixed that problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants