1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Amazon FBM × ヤマトB2クラウドの出荷作業を無料ブラウザツールで自動化した

1
Posted at

Amazon FBM × ヤマトB2クラウドの出荷作業を無料ブラウザツールで自動化した

はじめに

Amazon FBM(自己発送)を運用していると、毎日2つの地味な手作業が発生します。

  1. Amazon未出荷注文レポート(TSV)を手動でヤマトB2クラウド用のCSVに変換して送り状を発行する
  2. ラベル発行後、ヤマトの発行済みデータCSVをAmazonセラーセントラルの出荷通知形式に変換してアップロードする

この変換作業、件数が多い日は20〜30分かかるのに、ルールは決まりきっています。「なぜ手でやってるんだ」という典型例です。

今回、これをブラウザだけで完結する無料ツールとして作り、GitHubで公開しました。

ツールURL: https://ec-tools-jp.github.io/fbm-tool/


作ったもの

単一HTMLファイル(index.html)のブラウザツールです。

  • サーバー不要、インストール不要
  • 入力データは外部に一切送信しない(全処理がブラウザ内完結)
  • Chrome / Edge 対応(File System Access API使用のためSafari非対応)
  • 複数店舗対応(依頼主情報は設定画面からlocalStorageに保存)

STEP 1:Amazon未出荷TSV → ヤマトB2クラウド取込CSV

Amazonセラーセントラルからダウンロードした未出荷注文レポート(タブ区切り、UTF-8 or Shift-JIS)を、B2クラウドの取込形式(95列、Shift-JIS、全フィールドダブルクォート、CRLF)に変換します。

  • 同一order-idの複数商品を1行にグループ化
  • 住所パターンの3分岐処理(ship-address-2 が数字始まり/文字始まり/ship-address-3 あり)
  • 出荷予定日・送り状種類(ネコポス/宅急便/宅急便コンパクト)を選択可能

STEP 2:ヤマト発行済みデータCSV → Amazon出荷通知TXT

B2クラウドのラベル発行後にエクスポートする「発行済みデータCSV」(yyyymmddHHMMSS_発行済テ_ータ.csv)を読み込み、Amazonの出荷通知形式(タブ区切り、Shift-JIS、3行ヘッダー必須、CRLF)に変換します。

  • ご依頼主名 列で複数店舗を自動識別・ファイル分割
  • 伝票番号の .0 サフィックスを除去(Excelが数値として読み込んだ場合の対策)
  • 同日2本目以降は _2.txt_3.txt と自動採番

技術的なポイント

Shift-JIS の入出力

ヤマトB2クラウドのCSVはShift-JIS固定です。ブラウザのネイティブAPIはUTF-8しか扱えないため、encoding-japanese(v2)をCDNから読み込んで対応しています。

// 入力(自動検出)
function decodeBuffer(buffer) {
  const uint8 = new Uint8Array(buffer);
  const detected = Encoding.detect(uint8) || 'SJIS';
  const codes = Encoding.convert(uint8, { to: 'UNICODE', from: detected, type: 'array' });
  return Encoding.codeToString(codes).replace(/\r\n/g, '\n').replace(/\r/g, '\n');
}

// 出力(Shift-JIS に変換)
function toSjisUint8(text) {
  const codes = Encoding.stringToCode(text);
  return new Uint8Array(Encoding.convert(codes, { to: 'SJIS', from: 'UNICODE', type: 'array' }));
}

File System Access API でフォルダに直接書き込む

ZIPダウンロードやblob URLではなく、showDirectoryPicker() でユーザーが選んだフォルダにサブフォルダごと書き込みます。Chrome / Edge のみ対応。

const rootDir = await window.showDirectoryPicker({ mode: 'readwrite' });
const subDir  = await rootDir.getDirectoryHandle('B2クラウド_20260530', { create: true });
const fh      = await subDir.getFileHandle('b2cloud_20260530.csv', { create: true });
const wr      = await fh.createWritable();
await wr.write(toSjisUint8(csvText));
await wr.close();

住所の3パターン分岐

Amazonの住所フィールドは ship-address-1/2/3 の3列があり、運用パターンが3通りあります。

function buildAddress(state, city, addr1, addr2, addr3) {
  const base = [state, city, addr1].filter(Boolean).join('');
  const isNum = /^[\d0-9]/.test(addr2);
  if (addr3)           return { fullAddress: base + addr2, building: addr3 };
  if (!addr2 || isNum) return { fullAddress: base + addr2, building: '' };
  return { fullAddress: base, building: addr2 };
}

既知の制限・注意点

  • Safari非対応:File System Access APIがSafariで動作しません。Chrome / Edge で使用してください。
  • Amazon 90061警告:出荷通知アップロード後の処理レポートで「出荷元住所系の列が無効」という警告が出ますが、出荷通知は正常に処理されます。実害なし。
  • B2クラウドへの自動エクスポートは非対応:ラベル発行は人間の判断ステップを含むため、発行済みデータのエクスポートは手動で行ってください。

ソースコード・要望

GitHubで公開しています。バグ報告・機能要望はIssuesへどうぞ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?