# Order by LastUpdated with Python SDK

**URL:** <https://integration.keap.com/t/order-by-lastupdated-with-python-sdk/36991>\
**Category:** API Q&A\
**Created:** [April 12, 2018, 4:36pm UTC](https://integration.keap.com/t/order-by-lastupdated-with-python-sdk/36991 "2018-04-12T16:36:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dallas\_Huggins1](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dallas\_Huggins1](https://integration.keap.com/u/Dallas_Huggins1)\
**Post date:** [April 12, 2018, 4:36pm UTC](https://integration.keap.com/t/order-by-lastupdated-with-python-sdk/36991/1 "2018-04-12T16:36:37Z")

</div>

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](https://developer.infusionsoft.com/docs/xml-rpc/#data-query-a-data-table) 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!

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [April 12, 2018, 5:12pm UTC](https://integration.keap.com/t/order-by-lastupdated-with-python-sdk/36991/2 "2018-04-12T17:12:40Z")

</div>

I think you’re missing the ascending field after orderby

---

<div class="post-metadata">

**Author:** ![TomScott](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tomscott/32/67_2.png) [@TomScott](https://integration.keap.com/u/TomScott)\
**Post date:** [April 12, 2018, 5:15pm UTC](https://integration.keap.com/t/order-by-lastupdated-with-python-sdk/36991/3 "2018-04-12T17:15:09Z")

</div>

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.
