freakboy3742 / pyxero

Python API for accessing the REST API of the Xero accounting tool.
BSD 3-Clause "New" or "Revised" License
280 stars 208 forks source link

Cannot filter on payroll methods #160

Open ari opened 8 years ago

ari commented 8 years ago
Traceback (most recent call last):
  File "payroll.py", line 11, in <module>
    print xero.payrollAPI.payruns.filter(raw='PayRunStatus = POSTED')
  File "/usr/local/lib/python2.7/site-packages/xero/basemanager.py", line 195, in wrapper
    raise XeroBadRequest(response)
  File "/usr/local/lib/python2.7/site-packages/xero/exceptions.py", line 33, in __init__
    self.errors = [payload['oauth_problem'][0]]
KeyError: 'oauth_problem'

This isn't an oauth problem because "print xero.payrollAPI.payruns.all()" works fine. Can we get the exception giving us more detail about the specific request/response which Xero doesn't like?

ari commented 8 years ago

I've discovered the specific cause of this problem. The filter should be 'PayRunStatus == POSTED' instead of with a single =.

I'll leave this open however. Is it possible for this library to return more helpful error messages, or is this all we get back from Xero?

jvfiel commented 5 years ago

having the same issue but even without filter.

baptvit commented 5 years ago

Same issue its seen like an authentication problem in Xero's API. I've tried with differents methods.

baptvit commented 5 years ago

I may find the error cause. I gues if you are using a trial account, maybe you doesnt have permission to retrive those informartions. You will need atleast "Standard or Advisor level user with the Payroll Admin permission set." According to the documentation API https://developer.xero.com/documentation/payroll-api/integration-guide

camrail commented 4 years ago

+1 on catching this error better.

I was trying to download attachments however hadn't added the XeroScopes.ACCOUNTING_ATTACHMENTS scope.

Error was: File "/usr/local/lib/python3.6/dist-packages/xero/exceptions.py", line 75, in __init__ self.errors = [payload["oauth_problem"][0]] KeyError: 'oauth_problem'

Adding the above scope fixed it.

hyshka commented 4 years ago

For what it's worth, I have encountered a similar issue when making a request to the reports endpoint. Ex.

>>> trial_balance = self.xero.reports.get("TrialBalance")

KeyError: 'oauth_problem'
  ...truncated...
  File "xero/client.py", line 000, in get_trial_balance_report
    trial_balance = self.xero.reports.get("TrialBalance")
  File "xero/basemanager.py", line 244, in wrapper
    raise XeroUnauthorized(response)
  File "xero/exceptions.py", line 75, in __init__
    self.errors = [payload["oauth_problem"][0]]

In my case, I believe this was caused by a user who has authenticated with our application but has been assigned the "No Reports" role for that Xero Organisation as per the explanation in the Xero docs:

"An application that has been authorised by a Standard user with the "No reports" role will not be able to access the Reports or Journals endpoints (A HTTP 401 error will be returned in this case)." - https://developer.xero.com/documentation/api/reports

I think it's possible the 401 response from Xero, in this case, does not return a payload with "oauth_problem". We are still working on verifying this to be certain it is the cause.

+1 for catching these errors better.

bennett39 commented 2 years ago

+1 from me as well. I've got a response coming back with no oauth_problem field, and I'm receiving the same KeyError. In my case, it's also for reports:

report = client.reports.get('ProfitAndLoss', params={})
image

I'm doing some development against the sandbox account, so I suspect the underlying issue is permissions to retrieve reports. But would be nice to have a proper error message!