Skip to main content
Soracom

Docs

Soracom CLI Usage Guide

Manage SIMs and configure services from the command line.

Last updated:

Overview

Soracom CLI is a command line interface tool that allows you to control all aspects of your Soracom account, such as registering and managing SIMs, and configuring various Soracom platform services, from your terminal application rather than from the Soracom User Console.

While the Soracom User Console provides most users with an easy-to-use web-based interface, power users may prefer the simplicity of the command line. In addition, accessing your Soracom account from the command line allows you to control it programmatically, such as integrating SIM configuration commands into your own device management scripts, or using batch files to automate bulk operations.

Compared to Soracom API

Soracom CLI provides the same functionality as Soracom API. In fact, Soracom CLI is essentially a simple command-line HTTP client that is built on top of the Soracom API. This means that you can use the Soracom CLI to perform all of the same actions that you can perform using Soracom API.

However, whereas Soracom API simply provides a REST API which can be implemented into any type of application or programming environment that is capable of making HTTP requests (such as NodeJS, Python, PHP, and so on), Soracom CLI provides a pre-compiled binary executable that you can run directly from your terminal without any dependencies.

Compared to Soracom API, Soracom CLI provides two additional features:

  • Authentication - When working with the Soracom API, you must first generate an API Key and Token by submitting authentication credentials to the Authentication API. Once you have generated an API Key and Token, you can submit it in subsequent Soracom API requests. This two-step process helps ensure that your Soracom account is kept secure, however it requires additional effort to generate the API Key and Token before calling other Soracom API endpoints.

    Soracom CLI will perform the API Key and Token generation automatically, so that you can use a specific command directly without worrying about first generating the API Key and Token and specifying it in subsequent commands.

    In order for Soracom CLI to automatically generate an API Key and Token, it will use authentication credentials stored on your local machine. For more information, refer to the Configuration section below.

  • Automatic Pagination - Certain Soracom APIs will return data in the form of an array, such as getting a list of SIMs using the listSims API, or getting a list of groups using the listGroups API. By default, the Soracom API will return a maximum of 100 items in the array per request. In order to retrieve the next set of items, you must send another request to the API while specifying the ID of the last item in the previous request in order to perform pagination.

    Soracom CLI provides a --fetch-all flag for these commands which will repeat the requests in order to perform pagination automatically. This gives you the ability to retrieve all items in the array without having to worry about how to handle pagination.

As Soracom CLI runs as a command line executable, you may find it more suitable than the Soracom API for implementing into shell scripts or batch files, as you can trivially run the command and capture the output without manually creating and handling HTTP requests.

Installation

To use Soracom CLI on your machine, you must install the soracom executable file.

macOS

Soracom CLI can be installed on macOS directly using Homebrew from the terminal.

  1. Open the Terminal application.

  2. Use the brew tap command to add Soracom CLI as a third-party repository:

    brew tap soracom/soracom-cli

    This step may take a few minutes if you have not updated Homebrew recently.

  3. Install Soracom CLI:

    brew install soracom-cli
  4. Install the needed Bash shell command line completions:

    brew install bash-completion
  5. Confirm that Soracom CLI has been successfully installed:

    soracom version

    If Soracom CLI was installed successfully, it will return the version of the installed CLI tool.

Windows

  1. Visit the soracom/soracom-cli repository and download the latest release. For Windows, download one of the following files:
    • For 64-bit versions of Windows - Download the soracom_x.xx.x_windows_amd64.zip file
    • For 32-bit versions of Windows - Download the soracom_x.xx.x_windows_386.zip file

Depending on your Windows or anti-virus security settings, you may receive a warning when downloading the file. Follow your browser's prompt to bypass the warning and download or keep the file.

  1. Extract the contents of the zip file to your computer. You should have a soracom.exe executable file. Depending on your Windows settings, the .exe file extension may be hidden.

  2. Move the executable file to a directory on your computer, such as C:\Soracom, so that the path to the executable file becomes C:\Soracom\soracom.exe.

While you can use any path that you prefer, in some cases a long path or a path that contains spaces may result in errors.

At this point, you will be able to run the Soracom CLI from within the directory where the executable file is located. However, you may prefer to make the Soracom CLI accessible from any directory. To do so, simply follow the steps below to add the location to your Windows environment variables:

  1. Open the Start Menu, then type environment. Click the Edit the system environment variables shortcut:

    Start Menu
  2. From the System Properties dialog, click Environment Variables...:

    System Properties
  3. From the Environment Variables dialog, find the System variables section. From the list of system variables, click the Path item, then click the Edit... button:

    Environment Variables
  4. From the Edit environment variable dialog, click New, then enter the path to the directory where you saved the Soracom CLI executable file:

    Edit environment variables

    Then click the OK button for each of the Edit environment variable, Environment Variables, and System Properties dialogs.

  5. To ensure that the new environment variable is loaded correctly, reboot your computer.

  6. Once Windows has rebooted, you can open Command Prompt or PowerShell, then type the following command to confirm that Soracom CLI has been successfully installed:

    soracom version

    If Soracom CLI was installed successfully, it will return the version of the installed CLI tool.

Linux

The steps for installing Soracom CLI on Linux may differ based on your Linux distribution. The following instructions use Ubuntu as an example.

  1. Visit the soracom/soracom-cli repository and copy the download link for the latest release for your platform. For most Linux computers, copy the download link for one of the following files:

    • For 64-bit versions of Linux - Copy the soracom_x.xx.x_linux_amd64.tar.gz link
    • For 32-bit versions of Linux - Copy the soracom_x.xx.x_linux_386.tar.gz link
  2. Open your Terminal application, then download the file:

    wget https://github.com/soracom/soracom-cli/releases/download/vx.xx.x/soracom_x.xx.x_linux_amd64.tar.gz
  3. Extract the archive:

    tar xvf soracom_x.xx.x_linux_amd64.tar.gz
  4. Open the directory created in step 3:

    cd soracom_x.xx.x_linux_amd64/
  5. Copy the executable to the /usr/local/bin directory:

    sudo cp soracom /usr/local/bin
  6. Confirm that Soracom CLI has been successfully installed:

    soracom version

    If Soracom CLI was installed successfully, it will return the version of the installed CLI tool.

Upgrading

From time to time, a new version of Soracom CLI will be released to support new Soracom features and address bugs. If you are using an older version of Soracom CLI and a newer version is available, Soracom CLI will let you know that you can upgrade to the new version.

macOS

To install a new version of Soracom CLI on macOS, run the following command:

brew upgrade soracom-cli

Windows

To install a new version of Soracom CLI on Windows, follow steps 1-3 from the Windows installation instructions above, overwriting the older Soracom CLI executable file.

Linux

To install a new version of Soracom CLI on Linux, follow steps 1-5 from the Linux installation instructions above, overwriting the older Soracom CLI executable file.

Configuration

Before using Soracom CLI, you must configure your authentication method. The authentication method allows Soracom CLI to automatically perform authentication each time you run a Soracom CLI command.

You can configure Soracom CLI for any of the following authentication methods:

  • Authenticate using an AuthKey (AuthKey ID and AuthKey Secret). For more information on how to create an AuthKey, refer to the AuthKeys documentation.
  • Authenticate using your Operator credentials (root account email address and password).
  • Authenticate using SAM credentials (Operator ID, username, and password). For more information on how to create a SAM user, refer to the Users & Roles documentation.

Before configuring Soracom CLI, check that you have prepared one of the above authentication methods.

Soracom recommends configuring and using the AuthKey authentication method. An AuthKey may be generated for the root account (which will provide full administrative permissions), or may be generated for a SAM user (which itself can either be granted full permissions, or may be granted selective permissions).

By using an AuthKey, you can regularly update your root account or SAM user password without affecting your AuthKey usage, as well as separately revoke the AuthKey without affecting your ability to sign into the Soracom User Console.

  1. Start the Soracom CLI configure command:

    soracom configure
  2. When prompted, enter the Coverage Type you want to use. This will let Soracom CLI know to automatically use the specified coverage type when running commands.

    You can always override the default coverage type by adding a --coverage-type flag to any command.

    Please select which coverage type to use.
    
    1. Global
    2. Japan
    
    select (1-2) >
  3. Next, enter the authentication method you want to use. Follow the prompts to enter the authentication credentials according to the authentication method you selected:

    Please select which authentication method to use.
    
    1. Input AuthKeyId and AuthKey * Recommended *
    2. Input Operator credentials (Operator Email and Password)
    3. Input SAM credentials (OperatorId, User name and Password)
    
    select (1-3) >

Once the soracom configure command is complete, the authentication information and default coverage type are saved to a configuration file located in your user directory:

  • On macOS and Linux, the Soracom CLI configuration file will be stored in ~/.soracom/default.json
  • On Windows, the Soracom CLI configuration file will be stored in C:\Users\<username>\.soracom\default.json

The authentication credentials stored in the Soracom CLI configuration file are not encrypted. This means that anyone that gains access to your machine may be able to find your Soracom account credentials and access your Soracom account.

Profiles

If you are working with multiple Soracom accounts, or if you need to regularly switch between different SAM users each with different permission levels, you can create separate configuration profiles for Soracom CLI. Simply repeat the configuration steps above while using the --profile flag to specify a profile name:

soracom configure --profile myprofile

The Soracom CLI configuration file will be stored in ~/.soracom/myprofile.json on macOS/Linux or C:\Users\<username>\.soracom\myprofile.json on Windows.

Then to run the CLI for that profile, use the --profile flag on other commands accordingly:

soracom sims list --profile myprofile

To check which profiles are configured, use the configure list command (Soracom CLI v1.9.0 or later). It returns the profile names as a JSON array, or an empty array ([]) if no profiles are configured:

soracom configure list
[
  "default",
  "myprofile"
]

Unlike soracom configure get, which shows the contents of a profile including its credentials, configure list outputs only the profile names. Because the configuration files store credentials without encryption, use configure list when you need to know which profiles exist, such as in a script or when an AI agent operates the CLI on your behalf, instead of reading the configuration files directly.

Basic Usage

The help command can be appended to most Soracom CLI commands in order to output more information. For example, to list all available commands:

soracom help
A command line tool to invoke SORACOM API

Usage:
  soracom [command]

Available Commands:
  audit-logs           Retrieve audit logs.
  auth                 Performs authentication to access to the SORACOM API.
  bills                Show or export billing info.
  cell-locations       Retrieves cell tower location information.
  completion           Generate script for bash or zsh completion.
  configure            Show, create or update configurations (profiles).
  configure-sandbox    Create configurations (profiles) for API Sandbox.
  coupons              List or register coupons.
  credentials          List, create, update or delete credential sets.
  data                 Get stored data from subscribers.
  devices              Manage devices.
  diagnostics          Do diagnostics and get the reports.
  emails               Manage email addresses.
  event-handlers       List, create, update or delete event handlers.
  files                Manage files on Harvest Files.
  gadgets              Manage gadgets.
  groups               List, create, update or delete groups.
  help                 Help about any command
  lagoon               Manage Lagoon settings.
  logs                 List logs.
  lora-devices         Manage LoRa devices.
  lora-gateways        Manage LoRa gateways.
  lora-network-sets    Manage LoRa network sets.
  operator             Manage operators.
  orders               List, create or cancel orders.
  payer-information    Get or edit payer information.
  payment-history      List payment history.
  payment-methods      Create or update payment methods.
  payment-statements   List or export payment statements.
  port-mappings        Manage port mappings for on-demand remote access.
  products             List products.
  query                Search resources such as subscribers or sigfox devices.
  roles                List, create, update or delete roles.
  sandbox              Sandbox related operations.
  shipping-addresses   List, create, update or delete shipping addresses.
  sigfox-devices       Manage Sigfox devices.
  sims                 Manage SIMs.
  soralets             Manage Soralets for Orbit.
  stats                Show or export statistics.
  subscribers          Manage subscribers.
  system-notifications Manage system notifications.
  unconfigure          Remove configurations.
  users                Manage SAM users.
  version              Show version info.
  volume-discounts     Manage volume discounts (long-term discounts).
  vpg                  List, create, update or delete VPGs.

Then to learn about what commands are available for sims:

soracom sims help
Manage SIMs.

Usage:
  soracom sims [command]

Available Commands:
  activate                         Activate SIM.
  add-subscription                 Adds a new subscription container to a SIM profile
  attach-arc-credentials           Attach the credentials for Arc to a SIM.
  create                           Create a SIM.
  create-arc-session               Re-create an Arc session.
  create-packet-capture-session    Create Packet Capture Session
  deactivate                       Deactivate SIM.
  delete-country-mapping-entry     Delete subscription container mapping entries
  delete-packet-capture-session    Delete Packet Capture Session
  delete-session                   Delete Session
  delete-tag                       Delete SIM tag.
  disable-termination              Disable termination of the SIM.
  downlink-ping                    Send ping requests to a SIM.
  enable-subscription-container    Enables a subscription container.
  enable-termination               Enable termination of the SIM.
  get                              Get a SIM identified by sim_id
  get-data                         Get data sent from a SIM.
  get-packet-capture-session       Get Packet Capture Session
  list                             List SIMs.
  list-packet-capture-sessions     List Packet Capture Sessions
  list-subscription-containers     Get subscription container status.
  put-country-mapping-entries      Updates subscription container country mapping entries.
  put-tags                         Bulk insert or update SIM tags.
  register                         Register SIM.
  remove-arc-credentials           Remove the credentials for Arc from a SIM.
  report-local-info                Triggers SIM to report SIM local info.
  send-sms                         Send SMS to SIM
  session-events                   List Session Events.
  set-expiry-time                  Update expiry time of SIM.
  set-group                        Set Group id of a SIM.
  set-imei-lock                    Set IMEI lock configuration for the SIM.
  set-to-standby                   Set SIM to standby mode.
  stop-packet-capture-session      Stop SIM Packet Capture Session
  suspend                          Suspend SIM.
  terminate                        Terminate SIM.
  terminate-subscription-container Terminate subscription container
  unset-expiry-time                Delete expiry time of the SIM.
  unset-group                      Unset Group to SIM.
  unset-imei-lock                  Unset IMEI lock configuration for SIM.
  update-speed-class               Update SIM speed class.

Once you have found a command you want to use, use the --help flag to show information about how to use the specific command:

soracom sims activate --help
Change status of specified SIM to active.

Usage:
  soracom sims activate [flags]

Flags:
  -h, --help            help for activate
      --sim-id string   SIM ID of the target SIM.

To get the same information as machine-readable JSON, use the describe command. For more information, refer to the Automation and AI Agents section below.

Automation and AI Agents

Soracom CLI provides features that make it easier to drive the CLI from scripts and AI agents, such as discovering commands and their parameters, previewing requests before sending them, and handling errors programmatically. The Tips for AI Agents section below also describes how to use other Soracom CLI features safely and efficiently with an AI agent.

The features described in the Describing Commands, Previewing Requests, and Handling Errors sections require Soracom CLI v1.9.0 or later. To check your installed version, run soracom version. To upgrade, refer to the Upgrading section. Unless otherwise noted, the features described in the Tips for AI Agents section are also available in earlier versions.

Describing Commands

The describe command outputs commands and their parameters as JSON. This lets scripts and AI agents find out what a command accepts without parsing the text output of --help.

To list the top-level commands along with the number of subcommands each one has:

soracom describe
[
  {
    "command": "analysis",
    "summary": "Manage database queries.",
    "commands": 3
  },
  ...
]

To list every command, add the --all flag. Commands that call a Soracom API also include the HTTP method and path of the API:

soracom describe --all

To list the commands in a command group, specify the group name:

soracom describe sims
[
  {
    "command": "sims activate",
    "method": "POST",
    "path": "/sims/{sim_id}/activate",
    "summary": "Activate SIM"
  },
  ...
]

To get the details of a specific command, specify the full command. The output includes the command's parameters, request body, and response schema, along with the type of each value, whether it is required, and any allowed values:

soracom describe sims update-speed-class
{
  "command": "sims update-speed-class",
  "method": "POST",
  "path": "/sims/{sim_id}/update_speed_class",
  "summary": "Updates the IoT SIM speed class",
  "description": "Updates the IoT SIM speed class.",
  "parameters": [
    {
      "name": "sim_id",
      "option": "sim-id",
      "in": "path",
      "type": "string",
      "required": true,
      "description": "SIM ID of the target SIM."
    }
  ],
  "requestBody": {
    "contentType": "application/json",
    "type": "object",
    "schema": "UpdateSpeedClassRequest",
    "required": ["speedClass"],
    "properties": [
      {
        "name": "speedClass",
        "option": "speed-class",
        "in": "body",
        "type": "string",
        "required": true,
        "description": "Speed class. ...",
        "enum": ["s1.minimum", "s1.slow", "s1.standard", "s1.fast", "s1.4xfast", "s1.8xfast", "u1.standard", "u1.slow"]
      }
    ]
  },
  "response": {
    "type": "object",
    "schema": "Sim",
    "fields": [ ... ]
  }
}

The option field shows the name of the flag to specify on the command line (in this example, --sim-id and --speed-class). The enum field lists the values that you can specify.

Previewing Requests

Add the --dry-run flag to any command to output the HTTP request (method, URL, headers, and body) that would be sent, as JSON. With this flag, Soracom CLI does not call the API or perform authentication over the network, so you can check a request before it causes any changes to your account.

The request body is output exactly as you supplied it. If the body contains credentials, such as a password or an AuthKey Secret, they appear in the output, so handle the output with care.

For example:

soracom sims update-speed-class --sim-id 8981100000000000000 --speed-class s1.4xfast --dry-run
{
  "body": {
    "speedClass": "s1.4xfast"
  },
  "dryRun": true,
  "headers": {
    "Content-Type": "application/json",
    "User-Agent": "soracom-cli/1.9.0",
    "X-Soracom-Lang": "en"
  },
  "method": "POST",
  "url": "https://api.soracom.io/v1/sims/8981100000000000000/update_speed_class"
}

Secret headers and headers supplied by your profile are redacted. For example, the values of X-Soracom-Api-Key and X-Soracom-Token are shown as <hidden>.

Handling Errors

By default, Soracom CLI outputs errors as text. To output errors as JSON instead, set the SORACOM_JSON_ERRORS environment variable to any non-empty value:

set SORACOM_JSON_ERRORS=1
$env:SORACOM_JSON_ERRORS = "1"
export SORACOM_JSON_ERRORS=1

Errors are written to the standard error output:

  • For errors returned by the Soracom API, the API's JSON error response is output as-is. For example:

    {"code":"AGW0011", "message":"Invalid API Key or Token"}
  • Other errors, such as a subcommand that does not exist, are output in an error object.

    For example, when you specify a subcommand that does not exist without setting SORACOM_JSON_ERRORS, Soracom CLI outputs the error message followed by the command's usage as human-readable text:

    soracom sims foo
    Error: unknown command "foo" for "soracom sims"
    Usage:
      soracom sims [flags]
      soracom sims [command]
    
    Available Commands:
      ...

    When SORACOM_JSON_ERRORS is set, only the error message is output as JSON:

    SORACOM_JSON_ERRORS=1 soracom sims foo
    {"error":{"message":"unknown command \"foo\" for \"soracom sims\""}}

When you specify a subcommand that does not exist, such as soracom sims foo, Soracom CLI exits with a non-zero exit code, regardless of the SORACOM_JSON_ERRORS setting. Scripts and AI agents can use the exit code to detect a mistyped command.

Tips for AI Agents

When an AI agent operates Soracom CLI on your behalf, the following practices help keep its output manageable, protect your credentials, and limit the effects of unintended commands.

Keep the Output Small

Many commands that return an array, such as sims list, accept the --jsonl flag, which outputs one array element per line in JSON Lines format. Combined with the --fetch-all flag, which performs pagination automatically, a command can return a very large amount of data. To keep the agent's context small, pipe the output into a tool such as jq or head so that only the fields the agent needs are passed to it:

soracom sims list --fetch-all --jsonl | jq -c '{simId, status}'

Only commands that show --fetch-all or --jsonl in their --help output support these flags. You can also check the parameters of a command with the describe command (Soracom CLI v1.9.0 or later).

Give the Agent a Limited Credential

An AI agent may run commands that you did not intend, for example as a result of a prompt injection. Instead of an AuthKey for the root user, give the agent an AuthKey for a SAM user whose permissions are limited to what the task requires. For more information, refer to the Users & Roles documentation.

To prevent the agent from using your other profiles, set the SORACOM_PROFILE_DIR environment variable to change the directory where Soracom CLI stores and reads profiles, and create a profile that contains only the agent's credentials in that directory:

set SORACOM_PROFILE_DIR=%USERPROFILE%\.soracom-agent
soracom configure --profile agent
$env:SORACOM_PROFILE_DIR = "$env:USERPROFILE\.soracom-agent"
soracom configure --profile agent
export SORACOM_PROFILE_DIR=$HOME/.soracom-agent
soracom configure --profile agent

In this example, the profile is saved as agent.json in the .soracom-agent directory under your home directory. Set the same SORACOM_PROFILE_DIR environment variable when you run the AI agent so that Soracom CLI reads profiles only from that directory.

Keep Credentials Out of Files and Command Lines

Instead of storing credentials in a profile, you can have Soracom CLI get them from a command each time it runs. The command prints the credentials as JSON to the standard output, for example by retrieving them from a password manager. This keeps credentials out of profile files, which are stored without encryption.

Create a profile file that contains only the coverage type and the command in the profile directory (~/.soracom on macOS and Linux or C:\Users\<username>\.soracom on Windows by default, or the directory specified by SORACOM_PROFILE_DIR). For example, save the following as agent.json:

{
  "coverageType": "jp",
  "profileCommand": "/path/to/print-credentials.sh"
}

Set coverageType to g for Global coverage or jp for Japan coverage.

On macOS and Linux, allow only your user to read and write the profile file (for example, chmod 600 agent.json). Soracom CLI refuses to use a profile file whose permissions are too open.

Then specify the profile when running commands:

soracom sims list --profile agent

The command must print the credentials in the same format as a profile file, for example:

{"authKeyId": "<AUTH-KEY-ID>", "authKey": "<AUTH-KEY-SECRET>"}

Soracom CLI uses only the credentials from the command's output: authKeyId and authKey for an AuthKey, operatorId, username, and password for a SAM user, or email and password for the root user. Make the command output only one of these sets. If the output contains more than one set, the first set in this order takes precedence, and the other sets are not used even if authentication with that set fails. Other fields, such as coverageType, are ignored. The coverage type comes from the profile file.

Alternatively, specify the command with the --profile-command flag. In this case, also specify the --coverage-type flag. Without it, Soracom CLI uses the coverage type of the default profile, or Japan coverage if there is no default profile:

soracom sims list --profile-command "/path/to/print-credentials.sh" --coverage-type jp

Do not combine the --profile-command flag with the --profile flag. The credentials would come from the command, but the API endpoint would come from the profile specified by --profile.

If the default profile is for the API Sandbox, requests made with the --profile-command flag are sent to the API Sandbox even when you specify the --coverage-type flag.

Soracom CLI runs the command directly, not through a shell, so pipes (|), redirects, and environment variables such as $HOME in the command are not processed. Put such logic in a script and specify the path to the script.

Avoid having the agent pass the --auth-key-id and --auth-key flags directly on the command line. The AuthKey Secret remains in the agent's conversation log and in the shell history.

Pass the Request Body from a File or Standard Input

To specify a JSON request body without shell quoting and escaping mistakes, use --body @<file> to read the body from a file:

soracom sims update-speed-class --sim-id 8981100000000000000 --body @request.json

Or use --body - to read the body from the standard input:

echo '{"speedClass":"s1.fast"}' | soracom sims update-speed-class --sim-id 8981100000000000000 --body -

Check the Exit Code

When a newer version of Soracom CLI is available, a notice is written to the standard error output even if the command succeeds. Use the exit code, not the presence of output in the standard error output, to determine whether a command succeeded.

Disable Automatic Retries

By default, when the API returns an error, Soracom CLI retries the request several times with backoff. To return the error immediately instead, add the --no-retry-on-error flag. This is useful when the agent's tool calls have a timeout.

soracom sims list --no-retry-on-error

Output Request Details for Debugging

Set the SORACOM_VERBOSE environment variable to 1 to output the HTTP requests that Soracom CLI sends, including their headers and body, and the headers of the responses to the standard error output:

set SORACOM_VERBOSE=1
$env:SORACOM_VERBOSE = "1"
SORACOM_VERBOSE=1 soracom sims list

SORACOM_VERBOSE also outputs the requests that Soracom CLI sends to authenticate, and their body contains your AuthKey Secret or password. Only the values of the X-Soracom-Api-Key and X-Soracom-Token headers are redacted; other headers, such as those specified in the headers field of your profile, are output as-is.

Set SORACOM_VERBOSE only when you need to investigate a problem, and unset it afterward. Before you save or share the output, make sure that it contains no credentials.

Examples

Getting a List of SIMs

To output a list of SIMs:

soracom sims list

By default, the sims list command will return the first 100 SIMs in your account. Normally, you will need to repeat the command while specifying the last SIM in the response in order to retrieve the next 100 SIMs. However, you can use the --fetch-all flag to perform this pagination automatically and retrieve all SIMs at once:

soracom sims list --fetch-all

The data will be returned in JSON format. If you have the jq command installed on your system, you can pipe the JSON output in order to process the response. For example, to get a simple list of all SIMs in your account based on their SIM ID:

soracom sims list --fetch-all | jq -r '.[] | .simId'

You can also use the jq command to include additional fields from each SIM, and format the output as a CSV list:

soracom sims list --fetch-all | jq -r '.[] | [.simId, .tags.name, .status, .group] | @csv'

Modifying a SIM

To deactivate a SIM using its SIM ID:

soracom sims deactivate --sim-id 8942310000012345678

Similarly, to suspend a SIM:

soracom sims suspend --sim-id 8942310000012345678

To see what other actions can be performed on a SIM:

soracom sims help

Modifying Multiple SIMs

If you have a file containing a list of SIMs that you want to deactivate, you can simply loop through the file and repeat the command for each line:

#!/bin/bash

while read iccid; do
    # Remove carriage return character in case the list was
    # formatted using Windows CR+LF instead of Unix LF
    iccid=$( echo $iccid | sed -e 's/\r$//' )

    printf "Deactivating $iccid... "

    # Call the deactivateSim API, suppress the output if the
    # call is successful, and output any errors
    soracom sims deactivate --sim-id "$iccid" > /dev/null

    # If the command did not return an error, output OK
    if [ $? -eq 0 ]; then echo "OK"; fi

done < sims-to-deactivate.txt
@echo off

for /F "tokens=1" %%i in (sims-to-deactivate.txt) do call :deactivateSim %%i
goto :EOF

:deactivateSim
    set ICCID=%1

    <nul set /p output=Deactivating %ICCID%...

    :: Call the deactivateSim API, suppress the output if the
    :: call is successful, and output any errors
    soracom sims deactivate --sim-id %ICCID% > nul

    :: If the command did not return an error, output OK
    if %errorlevel% equ 0 ( echo OK )

goto :EOF

Creating a Napter Session

The Napter service allows you to create an on-demand remote access session in order to remotely connect to a device. In some cases, the connection may be for a command line service such as SSH. Instead of creating an on-demand remote access session through the Soracom User Console, you can use the Soracom CLI inside of a script to automate the connection.

This example shell script allows you to pass the 15-digit IMSI of the SIM as an argument, and will then create the on-demand remote access session and automatically connect via SSH once the session is ready:

This script makes use of the jq command for parsing JSON responses returned by Soracom. Ensure that you are able to run the jq command from your terminal.

#!/bin/bash

# Port: The SSH port of your device
port=22

# User: The SSH login username
user="pi"

# Identity File: If you use SSH keys for authentication, uncomment the next line and
# enter the local path to your SSH private key.
# identity_file="~/.ssh/id_rsa"

# Duration: How long you want the Napter port mapping to last (seconds)
duration=300

# Script starts here ----------
imsi="$1" # Get the IMSI from the first argument

# Create Napter Port Mapping
echo "Creating Napter remote access session..."
body="{\"destination\":{\"imsi\":\"${imsi}\",\"port\":${port}},\"duration\":${duration}}"
port_mapping=$( soracom port-mappings create --body "$body" )
napter_ip=$( echo $port_mapping | jq -r .ipAddress )
napter_port=$( echo $port_mapping | jq -r .port )
echo "Created Napter port mapping: ${napter_ip}:${napter_port}"

# Start SSH
echo "Connecting to SSH (${napter_ip}:${napter_port})..."
sleep 1
echo
if [ -z "$identity_file" ]; then
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p${napter_port} ${user}@${napter_ip}
else
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i "${identity_file}" -p${napter_port} ${user}@${napter_ip}
fi

# Delete Napter Port Mapping after SSH connection closed
echo "SSH connection closed, deleting Napter port mapping (${napter_ip}:${napter_port})..."
soracom port-mappings delete --ip-address "${napter_ip}" --port "${napter_port}"

Save the shell script to a file such as napter.sh. Then to use it:

./napter.sh 295050012345678

Search

Esc to close / Enter to view results