---
title: "Apps ScriptでGoogle Sheetsの連絡先をBrevoに取り込む"
description: "同意確認、フィールドの対応付け、配信停止の保護、APIエラーの報告を行う、繰り返し実行可能なApps Scriptの例です。"
url: https://tajo.io/jp/blog/import-google-sheet-contacts-to-brevo-apps-script/
markdown: https://tajo.io/jp/blog/import-google-sheet-contacts-to-brevo-apps-script.md
lang: ja-JP
author: "Set Noa"
author_url: https://tajo.io/jp/set-noa/
published: 2026-04-30
updated: 2026-10-09
alternates: {en-US: /blog/import-google-sheet-contacts-to-brevo-apps-script.md, bg-BG: /bg/blog/import-google-sheet-contacts-to-brevo-apps-script.md, cs-CZ: /cz/blog/import-google-sheet-contacts-to-brevo-apps-script.md, de-DE: /de/blog/import-google-sheet-contacts-to-brevo-apps-script.md, da-DK: /dk/blog/import-google-sheet-contacts-to-brevo-apps-script.md, es-ES: /es/blog/import-google-sheet-contacts-to-brevo-apps-script.md, fr-FR: /fr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, el-GR: /gr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, hi-IN: /hi/blog/import-google-sheet-contacts-to-brevo-apps-script.md, id-ID: /in/blog/import-google-sheet-contacts-to-brevo-apps-script.md, hr-HR: /hr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, hu-HU: /hu/blog/import-google-sheet-contacts-to-brevo-apps-script.md, it-IT: /it/blog/import-google-sheet-contacts-to-brevo-apps-script.md, ko-KR: /kr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, ar-SA: /ar/blog/import-google-sheet-contacts-to-brevo-apps-script.md, nl-NL: /nl/blog/import-google-sheet-contacts-to-brevo-apps-script.md, no-NO: /no/blog/import-google-sheet-contacts-to-brevo-apps-script.md, pl-PL: /pl/blog/import-google-sheet-contacts-to-brevo-apps-script.md, pt-BR: /pt/blog/import-google-sheet-contacts-to-brevo-apps-script.md, ro-RO: /ro/blog/import-google-sheet-contacts-to-brevo-apps-script.md, ru-RU: /ru/blog/import-google-sheet-contacts-to-brevo-apps-script.md, sv-SE: /se/blog/import-google-sheet-contacts-to-brevo-apps-script.md, zh-CN: /zh-cn/blog/import-google-sheet-contacts-to-brevo-apps-script.md, sl-SI: /sl/blog/import-google-sheet-contacts-to-brevo-apps-script.md, sr-Latn-RS: /sr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, th-TH: /th/blog/import-google-sheet-contacts-to-brevo-apps-script.md, tr-TR: /tr/blog/import-google-sheet-contacts-to-brevo-apps-script.md, ur-PK: /ur/blog/import-google-sheet-contacts-to-brevo-apps-script.md, vi-VN: /vi/blog/import-google-sheet-contacts-to-brevo-apps-script.md, sk-SK: /sk/blog/import-google-sheet-contacts-to-brevo-apps-script.md}
---

[データ同期](https://tajo.io/jp/blog/?category=data-sync)

# Apps ScriptでGoogle Sheetsの連絡先をBrevoに取り込む

同意確認、フィールドの対応付け、配信停止の保護、APIエラーの報告を行う、繰り返し実行可能なApps Scriptの例です。

google apps script brevo

Sheetsの連絡先をBrevoに取り込むには？

Sheetにemail、firstName、lastName、consent列を作ります。BREVO\_API\_KEYをScript Propertiesに保存し、コードにリストIDを設定してsyncSheetToBrevoを実行します。同意した行だけを対象に、Brevoの配信停止を確認し、重複を除き、APIエラーで停止します。自分で管理するApps Scriptであり、標準搭載のコネクターではありません。

[詳しく見る](https://tajo.io/jp/blog/import-google-sheet-contacts-to-brevo-apps-script/#sheet%E3%81%A8%E3%83%AA%E3%82%B9%E3%83%88%E3%82%92%E6%BA%96%E5%82%99%E3%81%99%E3%82%8B)

| 送信元フィールド | 送信先フィールド | サンプル値 |
| --- | --- | --- |
| `email` | `email` | `alex@example.com` |
| `firstName` | `FNAME` | `Alex` |
| `lastName` | `LNAME` | `Example` |

イベント参加者12人を一度だけ書き出すのは簡単です。2回目には同じアドレスが重複し、別の人がBrevoで配信停止しているかもしれません。繰り返し実行する取り込みでは両方を確認する必要があります。

このスクリプトは[Brevoの連絡先の取得・作成・更新エンドポイント](https://developers.brevo.com/reference/create-contact)を使います。小規模な定期取り込み向けで、一括ローダーやGoogle Sheets標準コネクターではありません。メールは送りません。同意の証拠と運用は自分で管理します。

## Sheetとリストを準備する

`Contacts`タブに次の列名を正確に作ります。`consent`にはチェックボックスを使い、対象のマーケティング用途に同意した場合だけ`TRUE`にします。

| email | firstName | lastName | consent |
| --- | --- | --- | --- |
| [jane@example.com](mailto:jane@example.com) | Jane | Doe | TRUE |
| [alex@example.com](mailto:alex@example.com) | Alex | Lee | FALSE |

Brevoのリストを作成または選択し、数値IDを`LIST_ID`に設定します。`FNAME`と`LNAME`属性がBrevoに存在することを確認してください。対応付けるのはこの2つだけです。同意した日時と方法をSheetで証明できない場合は、元の記録を別に保管します。`TRUE`というセルだけでは証拠になりません。

**Extensions → Apps Script → Project Settings → Script Properties**で`BREVO_API_KEY`を追加します。プロパティはスクリプト利用者に共有されるため、編集権限を絞ってください。キーをセルやコードに書かないでください。[Googleのアクセス規則](https://developers.google.com/apps-script/guides/properties)も確認します。

## スクリプト

`Code.gs`を次の例に置き換え、初回実行前に`LIST_ID`を設定します。

```javascript
const LIST_ID = 42; // Replace with your existing Brevo list ID.
const TAB = 'Contacts';
const BASE = 'https://api.brevo.com/v3';

function syncSheetToBrevo() {
  const key = PropertiesService.getScriptProperties().getProperty('BREVO_API_KEY');
  if (!key) throw new Error('Set BREVO_API_KEY in Script Properties first');
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(TAB);
  if (!sheet) throw new Error('Contacts tab missing');
  const values = sheet.getDataRange().getValues();
  const headers = values.shift().map(h => String(h).trim());
  const columns = ['email', 'firstName', 'lastName', 'consent']
    .map(name => headers.indexOf(name));
  if (columns.includes(-1)) throw new Error('Required header missing');
  const [emailCol, firstCol, lastCol, consentCol] = columns;
  const seen = new Set();
  const result = { written: 0, skipped: 0 };

  for (const row of values) {
    const email = String(row[emailCol] || '').trim().toLowerCase();
    if (row[consentCol] !== true || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email) || seen.has(email)) {
      result.skipped++;
      continue;
    }
    seen.add(email);
    const path = '/contacts/' + encodeURIComponent(email);
    const current = brevo_(key, path, 'get');
    if (current.code !== 200 && current.code !== 404) {
      throw new Error(`Contact read failed (${current.code}) for row ${result.written + result.skipped + 2}`);
    }
    if (current.code === 200) {
      const contact = JSON.parse(current.text);
      if (contact.emailBlacklisted || (contact.listUnsubscribed || []).includes(LIST_ID)) {
        result.skipped++;
        continue;
      }
    }
    const attributes = {};
    if (row[firstCol] !== '') attributes.FNAME = String(row[firstCol]);
    if (row[lastCol] !== '') attributes.LNAME = String(row[lastCol]);
    const body = { attributes, listIds: [LIST_ID] };
    const saved = current.code === 404
      ? brevo_(key, '/contacts', 'post', { email, ...body })
      : brevo_(key, path, 'put', body);
    if (![201, 204].includes(saved.code)) {
      throw new Error(`Contact write failed (${saved.code}) for ${email}: ${saved.text.slice(0, 200)}`);
    }
    result.written++;
  }
  Logger.log(JSON.stringify(result));
  return result;
}

function brevo_(key, path, method, body) {
  for (let attempt = 0; attempt < 3; attempt++) {
    const response = UrlFetchApp.fetch(BASE + path, {
      method,
      contentType: 'application/json',
      headers: { 'api-key': key },
      payload: body ? JSON.stringify(body) : undefined,
      muteHttpExceptions: true,
    });
    const code = response.getResponseCode();
    if (code !== 429) return { code, text: response.getContentText() };
    if (attempt === 2) return { code, text: response.getContentText() };
    const reset = Object.entries(response.getHeaders()).find(
      ([name]) => name.toLowerCase() === 'x-sib-ratelimit-reset'
    );
    const raw = Number(reset && reset[1]);
    const seconds = Number.isFinite(raw) && raw > 0 ? raw : 2 ** attempt;
    const waitSeconds = seconds + 2 ** attempt;
    if (waitSeconds > 60) return { code, text: response.getContentText() };
    Utilities.sleep(waitSeconds * 1000);
  }
}
```

保存後、`syncSheetToBrevo`を選び**Run**を押します。GoogleがSheetsと外部通信の権限を求めます。**Executions**で`{written, skipped}`ログを確認してください。取得結果が404なら作成、200なら更新します。それ以外のエラーは停止します。連絡先の書き込み成功は、キャンペーンの送信を意味しません。

スクリプトは1回の実行内で重複アドレスを除き、次の実行で再びBrevoを照会します。`emailBlacklisted`を`false`にせず、メールアドレスも変えません。Brevoが全体ブロックまたは対象リストからの配信停止を示す場合、Sheetが`TRUE`でもその行を除きます。配信停止の解除には使わないでください。[Brevoは](https://developers.brevo.com/reference/update-contact)、ブロックされた連絡先のアドレス変更がブロック解除につながる可能性を示しています。

## 定期実行前に一度確認する

自分が管理するテストリストと連絡先を使います。`TRUE`の行、`FALSE`の行、重複メールを含めると、書き込み1件とスキップ2件が期待されます。テスト連絡先をBrevoで配信停止して再実行し、その人に書き込みがないことを確認します。エラー確認では`LIST_ID`を一時的に無効にし、**Executions**のHTTPエラーを見てから戻して再実行します。実際の顧客データで試さないでください。このコードはモックBrevo応答でローカル検証しており、ライブの書き込みはしていません。

**Apps Script → Triggers → Add Trigger**で`syncSheetToBrevo`と時間間隔を選びます。[トリガーは作成者のアカウントで実行されます](https://developers.google.com/apps-script/guides/triggers/installable)。そのアカウントにSheetへのアクセスが必要です。小さなSheetなら毎日から始め、失敗を確認してください。Googleは[実行時間とURL Fetchを制限します](https://developers.google.com/apps-script/guides/services/quotas)。大きなデータは上限付きの作業に分けます。

429では`x-sib-ratelimit-reset`を読み、最大2回だけ再試行します。必要な待機が60秒を超えれば早く試さず、429を返して次回に任せます。ほかのエラーも停止し、次回は先頭から始まります。取得から書き込みまでの間に配信停止される可能性があります。この短い競合期間を許容できる場合だけ使ってください。厳密な保護にはイベント照合、信頼できる同意記録、送信直前の確認が必要です。

大きなSheetには[Brevoの非同期インポート](https://developers.brevo.com/reference/import-contacts)が`processId`を返します。これは処理の受付であって完了ではありません。結果を確認してください。ここでの連絡先ごとの処理なら、失敗した行が分かります。

## よくある質問

**Google Sheetsの標準コネクターは必要ですか？**

いいえ。Sheetに紐づくApps ScriptからBrevoの連絡先APIを呼びます。スクリプト、APIキー、定期トリガーは自分で管理します。

**どの行がBrevoに送られますか？**

consentがTRUEでメールアドレスが有効な行だけです。実行ごとに重複を除き、書き込み前にBrevoを確認します。

**再実行すると配信停止した人が再登録されますか？**

BrevoがemailBlacklistedまたは対象リストからの配信停止と示す連絡先は除きます。emailBlacklisted: falseを送らず、メールアドレスも変えません。本番前にはほかの同意・配信抑止情報も確認してください。

**失敗した実行をやり直すには？**

Apps Scriptの実行エラーを読み、原因を直して同じ関数を再実行します。同じメールとリストIDを使うため、成功済みの行で二人目の連絡先は作成されません。

## 関連記事

### [スクリプトでCSVまたはExcelの連絡先をBrevoにインポートする方法（Python、Node.js、cURL）](https://tajo.io/jp/blog/import-csv-contacts-to-brevo-with-a-script/)

2026年4月30日 · 6 分読む

CSV → Brevo

### [VBAマクロでExcelの連絡先をBrevoにプッシュする方法（Office Scriptsという代替案も）](https://tajo.io/jp/blog/import-excel-contacts-to-brevo-with-vba-macro/)

2026年4月30日 · 8 分読む

Microsoft Excel → Brevo

### [Brevo連携の選び方：動作を検証できる接続を選ぶ](https://tajo.io/jp/blog/brevo-connector-guide/)

2026年8月19日 · 5 分読む

6 セクション
