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

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

Open
ehawman-rosenberg opened this issue Jan 11, 2023 · 1 comment

Comments

@ehawman-rosenberg
Copy link
Contributor

ehawman-rosenberg commented Jan 11, 2023

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
Copy link

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.

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

2 participants