How to use filters on two answer terms with API?

  • larissahlewis
    Asked on June 17, 2024 at 3:33 AM

    I want to filter a form response by two answer terms. Is this possible and can you check my formatting.

    {

     "$and": [

       {

         "answers": {

           "32": {"prettyFormat:gt": "2024-06-17"  }

         }

       },

       {

         "answers": {

           "23": {  "prettyFormat": "Approved"       }    

     }

       }

     ]

    }

  • Raymond JotForm Support
    Replied on June 17, 2024 at 4:35 AM

    Hi larissahlewis,

    Thanks for reaching out to Jotform Support. So that we can assist you further, can you clarify if you're trying to receive submissions that includes these answers, or are you trying to filter responses to show only these field and answers? Also, please let us know the API call and language you're using. That will help us to better understand what’s going on.

    In the meantime, please check our API documentation on this link.

    Once we hear back from you, we'll be able to help you with this.

  • larissahlewis
    Replied on June 17, 2024 at 7:02 PM

    Apologies for not formulating the question well.

    For the API command https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}

    I want to filter returned results by specifying conditions in answer fields.

    "32" returns a date field I wish to be greater than a given date

    thus "answers": { "32": {"prettyFormat:gt": "2024-06-17"  } }

    and for field "23" to have a response of Approved

     "answers": { "23": {"prettyFormat": "Approved"  } }

    The API document only shows conditions at the top level of the JSON data structure and not how to use multiple conditions.

    Hope this clears up my request

  • Sonnyfer JotForm Support
    Replied on June 17, 2024 at 9:08 PM

    Hi larissahlewis,

    Thanks for clarifying. Can you try the following API endpoint instead? This should allow you to filter your submissions by date and approval status:

    https://api.jotform.com/form/{formID}/submissions?apiKey={API}&orderby[created_at]=desc&filter={"workflowStatus:ne":"Approve", "created_at:gt":"2024-06-17 00:00:00"}

    Give it a try and let us know if you need any more help.

  • larissahlewis
    Replied on June 17, 2024 at 9:51 PM

    Hi Sonnyfer. That suggestion does not work.

     "answers": "32" is a field that employee has requested to start their leave.

    "answers": "23" is a specific approval from a sub manager in the workflow.

    The date the form was created and overall approval status are not want I need to filter on.

  • Raymond JotForm Support
    Replied on June 17, 2024 at 10:22 PM

    Hi larissahlewis,

    With the Approval status, please use the following parameters:

    &filter={"workflowStatus":"Approve"}

    This works with the following:

    GET /submission/{submissionID}
    GET /form/{formID}/submissions

    Give it a try and let us know if you need any help.

  • larissahlewis
    Replied on June 18, 2024 at 7:31 AM

    Neither of these suggestions are helpful.

    I specifically only wish to return submissions that match multiple criteria within the answers section of the JSON file (not in the header sections that your answers suggest)

    For the API command https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}

    I want to filter returned results by specifying conditions in answer fields.

    "32" returns a date field I wish to be greater than a given date

    thus "answers": { "32": {"prettyFormat:gt": "2024-06-17"  } }

    and for field "23" to have a response of Approved

     "answers": { "23": {"prettyFormat": "Approved"  } }

    I DO NOT want to filter on workflowStatus state of Approved or on createdDates

  • Afzal JotForm Support
    Replied on June 18, 2024 at 9:29 AM

    Hi larissahlewis,

    I understand you're looking to filter form responses by two answer terms using the API. To filter submissions based on specific answer values, you can use the `filter` option in your API request. However, it's important to note that the Jotform API currently supports filtering based on basic submission information and does not support advanced filtering by question answers.

    For your specific case, where you want to filter by a date field greater than a certain date and another field with a specific response, you would typically need to retrieve all submissions and then programmatically filter them based on your criteria. Here's an example of how you might structure your API request to retrieve all submissions:

    https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}

    After retrieving the submissions, you can use your programming language of choice to loop through the results and apply your filters. 

    Let us know if there’s anything else we can help you with. 

 
Your Answer