pyxero icon indicating copy to clipboard operation
pyxero copied to clipboard

Cannot filter on payroll methods

Open ari opened this issue 7 years ago • 7 comments

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 avatar Oct 17 '16 01:10 ari

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?

ari avatar Oct 17 '16 03:10 ari

having the same issue but even without filter.

jvfiel avatar May 09 '19 11:05 jvfiel

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

helpthx avatar Jun 06 '19 14:06 helpthx

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

helpthx avatar Jun 07 '19 12:06 helpthx

+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.

camrail avatar Aug 10 '20 00:08 camrail

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.

hyshka avatar Oct 30 '20 19:10 hyshka

+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!

bennett39 avatar Mar 24 '22 18:03 bennett39