How to retrieve all submissions for a form?

Created on 6 May 2020, over 4 years ago
Updated 16 March 2023, almost 2 years ago

I am trying to retrieve all submissions for a given form. I see a method for retrieving a single webform submission (and this works for me). However, I see no method that would let me retrieve ALL submissions for a given form.

I tested the "Webform" path at /webform/{webform} thinking that might return basic config info about the form (maybe including info on the submissions), but this didn't work for me at all; it actually just tried to redirect me to the form itself.

I guess what I'm really asking is: how would I know a given webform submission ID unless I first get a list of submission IDs?

Is the idea that we would just use a view with a REST export for that? It might be helpful to add that to the documentation, so that people know this is by design, if that is indeed the case.

✨ Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States caspervoogt

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡¬Bulgaria vuil Bulgaria πŸ‡§πŸ‡¬ πŸ‡ͺπŸ‡Ί 🌍
  • πŸ‡¬πŸ‡§United Kingdom jamiep

    Updated #11 to fix "Entity queries must explicitly set whether the query should be access checked or not" errors in Drupal 10

  • First commit to issue fork.
  • πŸ‡¨πŸ‡¦Canada bryden

    I made a fork "3133989-retrieve-all-submissions-resource" which applies the patch from comment #13. I also made a small change:

    Instead of returning the webform submission data, I return the entity and the data keyed respectively. Each sid is an array with [entity] and [data] keys so that you can access the webform subsmission entity, or the data (responses). This can be useful for instance if you need to access the uuid so that you can use one of the other resources to patch a particular submission, or to retrieve a file, etc., which wasn't available in the submission data array.

  • Status changed to RTBC 12 months ago
  • πŸ‡¨πŸ‡¦Canada bryden

    Updating issue status

  • Status changed to Needs work 12 months ago
  • πŸ‡¦πŸ‡ΊAustralia imclean Tasmania
  • Status changed to Needs review 12 months ago
  • πŸ‡¨πŸ‡¦Canada bryden

    Contributing a patch based on the merge request so that these changes are available to developers using composer patches, until it gets merged.

  • Assigned to tunic
  • πŸ‡ͺπŸ‡ΈSpain tunic Madrid

    The functionality provided by the MR is working ok for me. However, I think the timestamp parameter is not enough because you can't define a range.

    I would like to replace it with an "after" and "before" params so you can define a time range.

  • πŸ‡ͺπŸ‡ΈSpain tunic Madrid

    Changes sent to the MR. I have changed more things that expected initially:

    Improvements:

    • Use StringTranslationTrait so $this->t() is used instead of t()
    • If there were no submissions the previous code returned an error. However, REST APIs usually don't consider an empty set an error because the request is fine, it is just the data returned happens to be empty. Now the code returns just an empty set as result.
    • Use HttpException for errors (like other plugins from this module). This simplifies error handling.
    • Change output structure renaming webform_submissions to just submissions. The URL already indicates this is a webform and I think response should not leak implementation details to API consumers.
    • Add parameters to define a time range ("after" and "before"). The timestamp parameter has been removed (or you could say it has been renamed because the "after" parameter works like the "timestamp" parameter) .
    • Removed the check for the existence of the webform_id because this is taken care in upper layers (a 404 page is returned if no webform id is provided)
  • Issue was unassigned.
  • πŸ‡ͺπŸ‡ΈSpain tunic Madrid

    I forgot to unassign me.

  • πŸ‡«πŸ‡·France mayeulk

    Hi. I needed a short code to get all submissions, as a text-based backup (to be able to verify that submissions are correctly saved). I do this, with PostgreSQL:

    pg_dump --dbname=postgresql://postgres@127.0.0.1:5432/postgres > /home/myself/backup/drupal_pg_backup.sql
    
    cat drupal_pg_backup.sql | grep ^my_second_webform_survey > results.csv

    where 'my_second_webform_survey' is the URL name of the survey I need.

    If you do not need the full sql backup, this works too:
    pg_dump --dbname=postgresql://postgres@127.0.0.1:5432/postgres | grep ^my_second_webform_survey > results.csv

    This gives the content of the public.webform_submission_data table (note there are other webform tables)
    The headers are:
    webform_id;sid;name;property;delta;value
    Similarly, you could get some of the other tables; for instance, the public.webform_submission table has these fields:
    sid,webform_id,uuid,langcode,serial,"token",uri,created,completed,changed,in_draft,current_page,remote_addr,uid,entity_type,entity_id,"locked",sticky,notes

Production build 0.71.5 2024