jotform / jotform-api-python

JotForm API - Python Client
GNU General Public License v2.0
39 stars 48 forks source link

filterArray not working as expected in jotformAPIClient.get_form_submissions() #27

Open ehawman-rosenberg opened 1 year ago

ehawman-rosenberg commented 1 year ago

jotformAPIClient.get_form_submissions() isn't using filterArray in a way in keeping with the docs. (also said docs incorrectly reference filter and orderby, instead of filterArray and order_by)


def get_submissions(api_key, set_form_ID, set_limit=100, set_debug=False):
    jotformAPIClient = jf.JotformAPIClient(api_key, debug=set_debug)
    return jotformAPIClient.get_form_submissions(
        formID=set_form_ID,
        limit=set_limit,
        # filterArray={
        #     "workflowStatus:eq":"In Progress",
        # },
        # order_by="created_at"
    )

Result: The 100 most recent submissions.


def get_submissions(api_key, set_form_ID, set_limit=100, set_debug=False):
    jotformAPIClient = jf.JotformAPIClient(api_key, debug=set_debug)
    return jotformAPIClient.get_form_submissions(
        formID=set_form_ID,
        limit=set_limit,
        filterArray={
            "workflowStatus:eq":"In Progress",
        },
        order_by="created_at"
    )

Result: None.


def get_submissions(api_key, set_form_ID, set_limit=100, set_debug=False):
    jotformAPIClient = jf.JotformAPIClient(api_key, debug=set_debug)
    return jotformAPIClient.get_form_submissions(
        formID=set_form_ID,
        limit=set_limit,
        filterArray={
            "workflowStatus:eq":"Approve",
        },
        order_by="created_at"
    )

Result: The oldest 25 results in the "Approved" workflowStatus. (Note the difference in workflowStatus name. Is there some hidden naming going on behind the scenes?)


def get_submissions(api_key, set_form_ID, set_limit=100, set_debug=False):
    # jotformAPIClient = jf.JotformAPIClient(api_key, debug=set_debug)
    # return jotformAPIClient.get_form_submissions(
    #     formID=set_form_ID,
    #     limit=set_limit,
    #     filterArray={
    #         "workflowStatus:eq":"In Progress",
    #     },
    #     order_by="created_at"
    # )
    url = f"https://api.jotform.com/form/{set_form_ID}/submissions?apiKey={api_key}&orderby[created_at]=desc&filter=\u007b%27workflowStatus:eq%27:%27In%20Progress%27\u007d&limit={set_limit}"
    req = urllib.request.Request(
        url,
        data=None,
        # headers are required to avoid a 403
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36"
        },
    )
    data_json = json.loads(urllib.request.urlopen(req).read())
    return data_json["content"]

Result: The 100 most recent submissions in the "In Progress" workflowStatus. (The desired outcome) EDIT: jokes, I just realized it's just the most recent submissions. sigh


Please reference this support ticket. The form I am working with is 220114796842154. https://www.jotform.com/answers/4751245-jotform-api-applying-filter-does-not-return-all-submissions/

viquanta commented 1 year ago

The issue stems from the relatively recently exposed workflowStatus field not being in the current Python API Client. I had to edit their class so a project would work. Another thing I discovered is the status value filters need to be in uppercase.

See this answer at JotForm: Issues With Workflow Status key in API. Scroll down to Umut's response at April 29, 2022 at 09:59 AM.