Skip to content

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

Open

Description

@shaunc869

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!

Activity

  1. jeremiahmarks commented on Jun 22, 2015

    @jeremiahmarks

    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]
  2. shaunc869 commented on Jun 22, 2015

    @shaunc869
    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?

  3. jeremiahmarks commented on Jun 22, 2015

    @jeremiahmarks

    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.

  4. abocado commented on Dec 2, 2016

    @abocado

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions