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

How do you query LastUpdated as being greater than or equal to? #10

Open
shaunc869 opened this issue Jun 21, 2015 · 4 comments
Open

How do you query LastUpdated as being greater than or equal to? #10

shaunc869 opened this issue Jun 21, 2015 · 4 comments

Comments

@shaunc869
Copy link

I am trying to run this query:

table = 'Contact'
returnFields = ['Id', 'FirstName', 'LastName', 'Email', 'Phone1']
query = {"LastUpdated": "2015-06-19T12:12:12+00:00"}
limit = 1000
page = 0
contacts = infusionsoft.DataService('query', table, limit, page, query, returnFields)

but as a greater than or equal to, how do I do that? Thanks!

@jeremiahmarks
Copy link

You would need to pull the results, and then parse them after you have them on your machine.

This is what I would use. You will notice that I remove the UTC offset part of your date, as it does not play well with sftrp.

I then convert it to a date time object, so that it can easily be used for evaluation. I then pull every contact record in the account, 1000 at a time. After I have all of the records, I use a list comprehension to find and return the records which match the criteria.

I hope that this helps!

import datetime
def getContactsUpdatedAfter(updatedDate="2015-06-19T12:12:12"):
    oldesttime=datetime.datetime.strptime(updatedDate, "%Y-%m-%dT%H:%M:%S")
    table = 'Contact'
    returnFields = ['Id', 'FirstName', 'LastName', 'Email', 'Phone1', "LastUpdated"]
    limit = 1000
    page = 0
    allreturnedcontacts=[]
    while True:
        thissetofcontacts = infusionsoft.DataService('query', table, limit, page, {}, returnFields)
        allreturnedcontacts += thissetofcontacts
        page+=1
        if len(thissetofcontacts)<1000:
            break
    return [c for c in allreturnedcontacts if c["LastUpdated"]>oldesttime]

@shaunc869
Copy link
Author

So if the purpose here is to sync the contacts for example and sync them every so often for changes I just end up syncing all contacts every time? These seems like a large limitation in the API, otherwise why have it as a query able field if you can't query it properly?

@jeremiahmarks
Copy link

I an not saying that this is the only way, it is just the way that I would do it. I imagine that you could order by lastupdated, and then only pull the groups of records that meet your criteria. It would be more work, imo, but you could do it.

@abocado
Copy link

abocado commented Dec 2, 2016

This should work.

table = 'Contact'
returnFields = ['Id', 'FirstName', 'LastName', 'Email', 'Phone1']
query = {"LastUpdated": "~>=~2016-11-01 ~<=~2016-12-31"}
limit = 1000
page = 0
contacts = infusionsoft.DataService('query', table, limit, page, query,
                                    returnFields)

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

3 participants