Sending data to Google Sheets with vanilla Javascript

A simple guide to sending your data to Google Sheets using vanilla Javascript

Picking a Google Sheet

Because Sheet Monkey automatically builds the columns, it may be easiest to start with a blank sheet if you already have a form and just want to connect it to a sheet. But if you're looking for something to help you get started, you can pick one of our templates. Sheet Monkey will automatically save the sheet with some initial columns in your Google Drive.

Once you create a form, Sheet Monkey will provide a form url or "form action" where you can start posting data. This unique action is all you need to post data into the Google Sheet.

Mapping the object keys to your sheet columns

Sheet Monkey will automatically match property names to Google Sheet columns. In the example of a mailing list, submitting the following object...

const data = {
    Email: 'steve.ballmer@microsoft.com',
    Name: 'Steve B.',
    Created: 'x-sheetmonkey-current-date-time'
};

...will create the following entry in the linked Google Sheet:

Posting your data

Sheet Monkey accepts textual data in application/json or mutipart/form-data encoding. You can pick either one of these when posting with Javascript.

Here's an example of how you can post data using JSON encoding.

const data = {
    Email: 'steve.ballmer@microsoft.com',
    Name: 'Steve B.',
    Created: 'x-sheetmonkey-current-date-time'
};

fetch('https://api.sheetmonkey.io/forms/vB1pUYCBvUqnSarEvAgsd6', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
}).then((result) => {
  // Handle the result
});

Responses

Error Status Codes:

  • 401 Indicates that the domain is blocked from submitting to this form.

  • 404 Indicates that the form could not be found.

  • 500 Indicates that an unexpected error occurred or the system may be down.

Success status codes:

  • 200 Indicates that the form was successfully submitted and the data should be added to the sheet.

Last updated