LoginSignup
2
0

More than 3 years have passed since last update.

soracom-cli で Sandbox 環境の見積作成や出荷をワンライナーで実行する

Last updated at Posted at 2019-12-20

はじめに

出荷済みとなったSIMの情報をバッチでDB取り込みしたり、タグ付けを行うのをテストするのにSandbox環境を利用しました。
何度もテストしたかったのでその際に作成したコマンドラインです。

以下の資料を参考にしています。
https://www.slideshare.net/SORACOM/soracom-conference-discovery-2018-f1-soracom

前提

以下が必要です。
環境はmacOSです。

  • soracom-cli がインストールされていること
  • jq がインストールされていること
  • SORACOM Sandboxでオペレーターが作成済であること

準備

発送先登録(初回のみ)

見積の作成に必要です。

以下のファイルを作成し、コマンドを実行する。

soracom operator get --profile sandbox | \
jq -r '.operatorId' | xargs -L 1 -I {} \
soracom shipping-addresses create \
--address-line1 "新宿" \
--address-line2 "6-27-30" \
--building "新宿イーストサイドスクエア" \
--city "新宿区" \
--company-name "テスト株式会社" \
--department "IT事業部" \
--full-name "山田太郎" \
--operator-id {} \
--phone-number "03-1234-5678" \
--state "東京都" \
--zip-code "1602222" \
--profile sandbox

SIMの発注

見積の作成、注文確定

必要な分だけ注文を発行します。
quentity が多いとどこかでbadrequestになった記憶がある。。。

soracom shipping-addresses list --profile sandbox \
| jq -r '.shippingAddresses[] | .shippingAddressId' \
| xargs -I {} soracom orders create \
--shipping-address-id {} \
--body '{"orderItemList":[{"productCode":"4573326590013","quantity":5}]}' \
--profile sandbox \
| jq -r '.orderId' | xargs -I {} soracom orders confirm --order-id {} --profile sandbox

確定済注文を出荷済みへ変更

複数の注文を一括で変更します。

soracom --profile sandbox orders list | \
jq '.orderList | map(select(.orderStatus == "orderProcessing"))' | \
jq -r '.[].orderId' | \
xargs -L 1 -I {} soracom sandbox orders ship \
--operator-id `soracom operator get --profile sandbox | jq -r '.operatorId'` \
--order-id {} \
--profile sandbox

↑だと毎回オペレータIDを取得すると思うので

OPERATOR_ID=`soracom operator get --profile sandbox | jq -r '.operatorId'`

soracom --profile sandbox orders list | \
jq '.orderList | map(select(.orderStatus == "orderProcessing"))' | \
jq -r '.[].orderId' | \
xargs -L 1 -I {} soracom sandbox orders ship \
--operator-id $OPERATOR_ID \
--order-id {} \
--profile sandbox
2
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
2
0