Shippo APIを使用して、CSVファイルからまとめた配送データを処理し、複数の配送ラベルを一括作成・購入したり、1日分の配送実績報告書(マニフェスト)を生成したりできます。
Process bulk shipments from CSV files, create and purchase batch labels, and generate end-of-day manifests via the Shippo API
一括購入により、認可されたShippoアカウント(配送管理サービス)から実際に料金が引き落とされます。PurchaseBatchを実行する前に、配送件数、配送業者・サービス、見積もり総額を表示し、ユーザーの明示的な確認を得てください。
PurchaseBatchを呼び出す前に、以下の内容をまとめて表示し、ユーザーの明示的な確認を得てください:
ユーザーの明示的な確認なしに進めないでください。
列の仕様についてはshippo/references/csv-format.mdを参照してください。
CSVを読み込んで解析します。必須列が存在することを確認し、行数を報告します。
各行の必須フィールドが空でないことを確認します。無効な行と理由を報告します。
国際配送の行を検出します(送信国≠受信国)。これらの行に対して税関申告書(通関手続きの書類)を作成します。shippo/references/customs-guide.mdを参照してください。正しい税関申告のコード値を使用してください:返品商品にはRETURN_MERCHANDISE(RETURNではなく)、慈善寄付にはHUMANITARIAN_DONATION(HUMANITARIANではなく)。
各行ごとに住所と荷物情報をまとめたbatch_shipments配列を構築します。
CreateBatchをこの配列で呼び出します。
GetBatchをポーリング(定期的に確認)して、ステータスがVALIDまたはINVALIDになるまで待ちます。以下の「ポーリング間隔」を参照してください。
ステータスがINVALIDの場合、バッチ内の一部の配送情報が検証に失敗しています。以下の「無効なバッチの修正」を参照し、修正してからVALIDになるまで再度ポーリングします。いずれにせよ、各配送の失敗内容を報告してから進みます。
購入を確認します(上記の「購入確認ゲート」を参照)。
PurchaseBatchを呼び出して、有効なすべての配送の配送ラベルを購入します。
GetBatchをポーリングして、ステータスがPURCHASINGからPURCHASEDに変わるまで待ちます。以下の「ポーリング間隔」を参照してください。
報告します:試行数、成功数、失敗数。成功時には:追跡番号とラベルURL(完全なURL)。失敗時には:エラーメッセージ。
購入済みバッチでは、各ラベルのURLがバッチオブジェクトに直接含まれません。batch_shipments[]の各エントリにはtransactionフィールド(トランザクションオブジェクトID)があります。これに対してGetTransactionを呼び出すと、その配送のlabel_urlとtracking_numberが得られます。バッチレベルのlabel_urlは複数ラベルの統合PDF(最大100ページ)であり、1件ごとに分割することはできません。
500件以上の配送の場合は、複数のバッチに分割することを検討してください。大規模なバッチは検証と購入に時間がかかり、単一の失敗の原因特定が難しくなります。
GetBatchで後で確認するよう提案してください。各配送ごとにCreateShipmentを呼び出して、料金見積もりを取得します(「料金比較」を参照)。
料金を提示します。ユーザーがサービスレベルのルール(例:「各配送で最安」または特定の配送業者・サービス)を選択します。
各アイテムにservicelevel_tokenを付けてbatch_shipmentsを構築します。
上記と同じように、作成、検証、購入を確認し、購入して報告します。
配送を追加:AddShipmentsToBatch(購入前のみ)。注意:無効な配送を追加すると、バッチ全体のステータスがINVALIDに変わります。追加後は各配送のステータスを確認してください。
配送を削除:RemoveShipmentsFromBatch(購入前のみ)。
GetBatchがステータスINVALIDを返した場合、1件以上のバッチ配送が検証に失敗しており、修正するまでバッチは購入できません。
失敗を特定します。 GetBatchをobject_results=creation_failedで呼び出して失敗した配送のみを取得します(多数ある場合は?page=でページネーション)。または、各batch_shipments[].status(VALID / INVALID / INCOMPLETE / TRANSACTION_FAILED)と理由を示すmessagesを読みます。バッチレベルのerrors配列に、同じ失敗内容がまとめられています。
修正します。以下のいずれか:
object_id(batch_shipments[]から取得、配送オブジェクトIDではなく)を指定してRemoveShipmentsFromBatchを呼び出して削除するか、AddShipmentsToBatchを呼び出します。GetBatchを再度ポーリングしてステータスがVALIDになるまで待ちます。
その後、購入を確認し(「購入確認ゲート」を参照)、PurchaseBatchを実行します。
以下を収集します:carrier_account(オブジェクトID)、shipment_date(YYYY-MM-DD形式、デフォルトは本日)、address_from(受け取り拠点の住所)。
必要に応じて、特定のトランザクションオブジェクトIDを収集してリストのスコープを絞ります。特定のトランザクションオブジェクトIDを指定する必要があります。日付範囲での自動含有はありません。
CreateManifestを呼び出します。
GetManifestをポーリングして、ステータスがSUCCESSまたはERRORになるまで待ちます。
マニフェスト(配送リスト)のPDF URLと配送件数を返します。
CSVバッチ:
CSVを解析 → CreateCustomsDeclaration(国際配送行) → CreateBatch → GetBatchをポーリング → 購入を確認 → PurchaseBatch → GetBatchをポーリング
配送リスト:
CreateManifest(トランザクションオブジェクトIDで指定) → GetManifestをポーリング
<!-- ⚠️ DO NOT EDIT. Auto-generated from skills/batch-shipping/SKILL.md by scripts/sync.js Edits here will be overwritten on the next sync. To change this content, edit the canonical source and re-run the sync script. -->
Batch purchases charge the authorized Shippo account for real. Before PurchaseBatch, show the shipment count, carrier/service, and estimated total cost, and require explicit user confirmation.
Before every call to PurchaseBatch, summarize the following and ask the user for explicit confirmation:
Do not proceed without explicit user confirmation.
See shippo/references/csv-format.md for the column specification.
shippo/references/customs-guide.md. Use correct customs enum values: RETURN_MERCHANDISE (not RETURN) for returned goods, HUMANITARIAN_DONATION (not HUMANITARIAN) for charitable donations.batch_shipments array with inline address and parcel objects per row.CreateBatch with the array.GetBatch until status is VALID or INVALID. See Polling Intervals below.INVALID, some batch shipments failed validation: see "Fixing an INVALID batch" below, fix them, and re-poll until VALID. Report per-shipment failures either way before proceeding.PurchaseBatch to buy labels for all valid shipments.GetBatch until status changes from PURCHASING to PURCHASED. See Polling Intervals below.A purchased batch does not put each label URL inline on the batch object. Each entry in batch_shipments[] carries a transaction field, which is a Transaction object_id. Call GetTransaction on it to get that shipment's label_url and tracking_number. The batch-level label_url is a merged multi-label PDF (up to 100 labels per file) and cannot be split per order.
For batches over 500 shipments, consider splitting into multiple batches. Large batches take longer to validate and purchase, and a single failure can be harder to diagnose.
GetBatch with the batch object_id.CreateShipment per shipment to get rate quotes (see Rate Shopping).batch_shipments with servicelevel_token per item.AddShipmentsToBatch (before purchase only). Note: adding an invalid shipment will change the entire batch status to INVALID. Check per-shipment statuses after adding.RemoveShipmentsFromBatch (before purchase only).If GetBatch returns status INVALID, one or more batch shipments failed validation and the batch cannot be purchased until they are fixed.
GetBatch with object_results=creation_failed to return only the failed shipments (paginate with ?page= if there are many), or read each batch_shipments[].status (VALID / INVALID / INCOMPLETE / TRANSACTION_FAILED) and its messages for the reason. The batch-level errors array collects the same per-shipment failures in one place.RemoveShipmentsFromBatch with the failed batch-shipment object_ids (from batch_shipments[].object_id, not the shipment object_id) to drop them, orAddShipmentsToBatch with corrected shipment objects (fixed address, parcel, or servicelevel).GetBatch until status is VALID.PurchaseBatch.carrier_account (object_id), shipment_date (YYYY-MM-DD, default today), address_from (pickup address).CreateManifest.GetManifest until status is SUCCESS or ERROR.CSV batch:
Parse CSV -> CreateCustomsDeclaration (international rows) -> CreateBatch -> poll GetBatch -> confirm -> PurchaseBatch -> poll GetBatch
Manifest:
CreateManifest (with transaction object_ids) -> poll GetManifest
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。