Order by LastUpdated with Python SDK

I am currently working on trying out the Python SDK because I need to get a list of contacts (along with other entities) that are ordered in descending order from the last updated date. The following query returns a list of Contacts.

table = 'Contact'
query = {}
limit = 1000
page = 0
returnFields = ['Id', 'FirstName', 'LastName', 'Email', 'LastUpdated']
response = infusionsoft.DataService('query', table, limit, page, query, returnFields)
print response

However, when I add in an orderBy field, the query returns the error:

(‘ERROR’, <Fault 0: ‘No method matching arguments: java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.util.HashMap, [Ljava.lang.Object;, java.lang.String’>)

This is the full query that throws the error:

table = 'Contact'
query = {}
limit = 1000
page = 0
returnFields = ['Id', 'FirstName', 'LastName', 'Email', 'LastUpdated']
orderBy = 'LastUpdated'
response = infusionsoft.DataService('query', table, limit, page, query, returnFields, orderBy)
print response

Is there something obvious I’m doing wrong? The API docs say that orderBy should be a string field in “which the results should be sorted by” and it appears other people online are using the functionality but I cannot find an example and it’s not working for me.

Any insight is greatly appreciated! Thanks!

I think you’re missing the ascending field after orderby

There are three variants of the Legacy XML-RPC DataService.Query method:

  • query(String key, String table, int limit, int page, Map<String, Object> queryData, Object selectedFields)
  • query(String key, String table, int limit, int page, Map<String, Object> queryData, Object selectedFields, String orderBy, boolean ascending)
  • query(String key, String table, int limit, int page, Map<String, Object> queryData, Object selectedFields, Object orderByFields, boolean ascending)

You must specify the full parameters of whichever you are using; in this case, if you specify an orderBy, you must also specify a boolean ascending parameter.

2 Likes