Submit Google Forms by curl command

Google Forms is a very common way to collect user data nowadays. After you have created the form, you could insert it to your web site and present it with your own style.

Other than that, we could integrate Google Forms with the backend job since we could submit the form through command line. Let’s take a look on the following example.

1. Create a new form on your Google drive. The edit page url should be in the following format.

  • https://docs.google.com/forms/d/<form-id>/edit

 

2. View the live form and inspect your field elements to get all the field name.
submit-google-form-by-command-1
 

3. Construct the curl command as follow:

  • curl https://docs.google.com/forms/d/<form-id>/formResponse -d ifq -d <field-name>=<field-value> -d submit=Submit

 

In my case the curl command is

  • curl https://docs.google.com/forms/d/1XEJWxStJhNhfv_smf9pzQxEBbXMjhyuRyp7aHXuDjRY/formResponse -d ifq -d entry.1202908243=Eureka -d submit=Submit

 

4. Execute it in shell and that return your the submitted successfully html.
submit-google-form-by-command-2
 

5. If your <field-value> contains special characters like whitespace, wrap the key value pair with double quote.

  • curl https://docs.google.com/forms/d/1XEJWxStJhNhfv_smf9pzQxEBbXMjhyuRyp7aHXuDjRY/formResponse -d ifq -d "entry.1202908243=Hello World" -d submit=Submit
  •  

    6. You could also submit the whole url without breaking down the parameters. in that case you need to encode the special characters like whitespace. For example if the text contains a whitespace, replace it with %20.

    • curl "https://docs.google.com/forms/d/1XEJWxStJhNhfv_smf9pzQxEBbXMjhyuRyp7aHXuDjRY/formResponse?ifq&entry.1202908243=Hello%20World&submit=Submit"

     

    6. Check the response spreadsheet.
    submit-google-form-by-command-3
     

    Done =)

    Reference: URL Tricks for Google Forms: Pre-populate, and Automatically Submitting Responses

    Update @ 2014-07-31: Thanks Philip for suggesting using the -d parameter in the curl command. =D

12 thoughts on “Submit Google Forms by curl command”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.