← Guides

Keep a Google Sheet up to date with your marketplace data

Have an AI assistant write a Google Apps Script that pulls yesterday's numbers into a sheet every morning, with no server to run.

Every morning, your sheet fills itself. A Summary tab shows yesterday's spend, sales, ACoS and orders for each account. A Campaigns tab lists every campaign for the day. An Inventory tab shows current stock. ACoS is ad spend divided by ad sales.

You do not write the script. Claude or ChatGPT writes it from the prompt below. The script lives inside the sheet, so there is no server to run.

What you need

  • A Build account at build.sellermate.ai with your accounts connected in the console.
  • A Google account and a new, empty Google Sheet.
  • An AI assistant: Claude or ChatGPT.

Apps Script is Google's built-in tool for running small scripts inside a Sheet. A trigger is a setting that runs one of those scripts on a schedule.

Steps

  1. Create a read-only API key. Open the Build console, go to API keys and create a key with read access only. Keys look like sm_live_.... The key is shown once, so copy it now.
  2. Open the script editor. In your sheet, choose Extensions, then Apps Script.
  3. Store the key. Go to Project Settings, scroll to Script Properties and add a property named BUILD_API_KEY. Paste the key as the value. Never put it in a cell or in the code.
  4. Paste the prompt below into your assistant.
  5. Paste the code it returns into the editor, replacing what is there. Save.
  6. Run it once by hand. Run the function the assistant names, usually syncYesterday. Google asks you to authorise the script. Accept.
  7. Add the trigger. Open Triggers, choose Add Trigger, pick syncYesterday, set the event source to Time-driven, then Day timer, then a morning hour such as 6am to 7am.

The prompt

Read the API docs at https://www.sellermate.ai/api-docs first.

Write a Google Apps Script that fills three tabs in this sheet with
yesterday's marketplace data.

Rules:
- Every tool is POST https://api.sellermate.ai/public/v1/tools/{name}
  with a JSON body. Use UrlFetchApp.fetch with method post,
  contentType application/json, an X-API-Key header and
  muteHttpExceptions set to true.
- Read the key with PropertiesService.getScriptProperties().
  Property name: BUILD_API_KEY. Never hard-code, log or write it
  to the sheet.
- Call get_user_context first and use the accounts it returns.
- "Yesterday" is one calendar day in the script's time zone. Use
  Utilities.formatDate with the same start_date and end_date.
- Summary tab: one row per account, with the date, spend, sales,
  ACoS and orders. Use get_marketplace_summary.
- Campaigns tab: one row per campaign with the account, date and
  its metrics. Use get_campaign_performance with page_size and
  keep requesting pages while pagination.hasMore is true.
- Inventory tab: use get_inventory, one row per product.
- Clear and rewrite the Campaigns and Inventory tabs each run.
  Append one dated row per account to Summary, so history builds up.
- On a 429 response, wait for the Retry-After header with
  Utilities.sleep, then retry. On any other error, stop and write
  the status and message to a Log tab.
- Stop before the 6 minute Apps Script limit and note it in Log.
- Export one function named syncYesterday for the trigger.

Check it

Open the Summary tab. Pick one account and compare yesterday's row with the same date in the Build console or in Seller Central. The totals should match.

If they do not, check the time zone. Open Project Settings and confirm it is the one your accounts report in. Then tell the assistant the exact date and run it again.

A few messages mean something specific:

  • 401: the key is wrong or revoked.
  • 403: the key cannot see that account.
  • 429: too many requests. The limit is 60 a minute on Free and Build, and 300 on Scale. The script should wait and retry.

Make it better later

Ask the assistant to add any of these once the base sync works:

  • A fourth tab for search terms, using get_search_term_performance.
  • A row that turns red when ACoS passes a number you set.
  • A chart on the Summary tab for the last 30 days.

Watch out for

  • Apps Script stops a run after 6 minutes. Page through campaign rows, keep each tab small, and pull only the columns you read. With many accounts, ask the assistant to sync a few per run.
  • Sharing the sheet shares the data, not the key. Viewers and editors see the numbers. Only people who can edit the script can see Script Properties, so give edit access sparingly.
  • Recent days move. Sales keep arriving for a few days after a click, so yesterday's numbers can shift a little. Report on finished periods when it matters.
  • Keep the key read-only. A sheet never needs to write back.
  • Your history is limited by your plan: 90 days on Free, 12 months on Build, 3 years on Scale.

Related use cases

Google Sheets that refresh themselves

Keep a spreadsheet up to date with your latest ads, orders and inventory.

Google Sheetsn8nAgencies · Brands · Developers

Try it on your own accounts.

Start free with one account.

Start freeMore guides