Skip to content
SheetCapture

Add rows to Google Sheets from Node.js

Send rows from any server, script or serverless function, such as order logs or app events.

  1. 1

    Get your sheet and access key ready

    Create a Google Sheet (headers are optional: we'll add a column for each field) and share it with this address as an Editor:

    sheetcapture@appspot.gserviceaccount.com

    Copy the sheet ID from its URL (the part between /d/ and /edit), and your access key from your account page. No account yet? Start free.

  2. 2

    Write a small helper

    Node 18 and later include fetch. Keep the key in an environment variable.

    export async function addRow(data) {
      const response = await fetch("https://www.sheetcapture.com/add-row", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.SHEETCAPTURE_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ GoogleSheetID: process.env.GOOGLE_SHEET_ID, data }),
      });
    
      if (!response.ok) {
        const { error, code } = await response.json();
        throw new Error(`SheetCapture ${code}: ${error}`);
      }
    
      // How many requests are left this month
      return Number(response.headers.get("X-Requests-Remaining"));
    }
  3. 3

    Call it from anywhere

    Each call adds one row. Objects and arrays are saved as JSON text.

    await addRow({
      Event: "order.created",
      Order: "1042",
      Total: "£48.00",
      Items: ["Mug", "Tea"],
    });

If Google is busy, you'll get a 503 with a Retry-After header. Wait that many seconds and try again.

Want every option?

The API docs cover responses, limits and error codes.

Read the docs