pyxero
pyxero copied to clipboard
Can't retrieve different 100 lines from "journals"
Every trial returns the same 100 lines.
I tried: #using since journals = xero.journals.filter(since=datetime(2013, 1, 1)) journals = xero.journals.filter(since=datetime(2017, 1, 1)) #using page journals = xero.journals.filter(page=1) journals = xero.journals.filter(page=2) #combining parameters iterating over page number like: page =1, page = 2, page =3 journals = xero.journals.filter(since=datetime(2013, 1, 1), page=<page_number>)
Please, does anyone know how to extract the content of "journals" properly?
Thanks in advance.
@schinckel @calvin @blebo @freakboy3742
From what I understood, since
is filtering by modified date, not journal creation date, which is a bit surprising. And it's sorted from oldest to newest.
As we needed only the last 6 months, we were using since
to get a journal number in the past, and then using offset
with the journal number to get all the journals until now.
Probably not the most elegant way, probably better ways to do it, not explaining everything that happens to you, but if it can give you some hints...
First of all, thank you @romgar for your reply! Would you know a way to retrieve all journals from 01/01/2015 up to now? Cheers!
Hi Team,
I am facing same issue here. Any solution as of now?
Thanks
this still seems to be an issue
Repeat of my response in #186
I have just gone through the PyXero SDK as well as re-creating my own requests/oauth 1 mini package to test and believe this is due to the page parameter being passed.
The journals endpoint only accepts the offset parameter.
I have tried to pass this as follows: image
And can see the params and headers added: image
But still pyXero doesn't seem to construct the correct endpoint as no matter what offset passed, same resultset. Xero has 288 journals in the dmeo company so shouldn't be seeing the same when offsetting like I have (numerous different offset values)
On the dummy one I recreated I got it to successfully paginate using offset, core of that code is:
` import requests from requests_oauthlib import OAuth1 from oauthlib.oauth1 import SIGNATURE_RSA, SIGNATURE_TYPE_AUTH_HEADER
#Define client key consumer_key = 'my consumer key'
#read rsa_key with open('<my .pem file>') as keyfile: key = keyfile.read()
#create header and make get request in line with guidance #from https://requests-oauthlib.readthedocs.io/en/latest/oauth1_workflow.html
#Create Header headeroauth = OAuth1(consumer_key, resource_owner_key=consumer_key, signature_method=SIGNATURE_RSA, rsa_key=key, signature_type=SIGNATURE_TYPE_AUTH_HEADER)
#Base Url url = 'https://api.xero.com/api.xro/2.0/journals'
#Create Headers headers = {} headers['Accept'] = 'application/json' headers['User-Agent'] = 'testPyXeroThing'
#Dict to hold response text resp = {}
#Test range to paginate using offset for i in range(0, 5): url2 = url + '?offset='+str(i*100) print(url2) r = requests.get(url2, auth=headeroauth, headers=headers) resp[i] = r.text
#write results to file for t in resp: with open('test.txt', 'a+') as f: f.write(r.text)
`