All CLI command output is sent to stdout
, and can be customized in terms of output values as well as format.
By default, any output is formatted in a human-readable, columnar format like so:
1$ twilio phone-numbers:list2SID Phone Number Friendly Name3PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1209242XXXX SIP testing4PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1646887XXXX Congress hotline5PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1209337XXXX DAVID'S SECRET CRUSH
Many list
commands will allow you to specify a --properties
option defining which columns you'd like to display. For example, to display only the Phone Number and SMS URL columns, you would pass --properties "phoneNumber, smsUrl"
.
1$ twilio phone-numbers:list --properties 'phoneNumber, smsUrl'2Phone Number SMS URL3+1209242XXXX https://very-secret.ngrok.io/sms4+1646887XXXX https://handler.twilio.com/twiml/EHxxxx5+1209337XXXX
Column names must match the camelCased JSON property names in the Twilio API for the resource. For example, you can find the possible column values for phone numbers by looking at the Incoming Phone Number API Reference
The default list of properties varies by command, and is subject to change with each release.
Append the -o json
flag to a command to change the output format to JSON. When you choose JSON, the command will send the entire API response to stdout
as JSON.
You can then pipe this output to tools like jq to parse the JSON as necessary.
For example:
1# Fetch all incoming phone numbers as json, and display as an array2# that only contains each sid and phone number.3$ twilio phone-numbers:list -o json \4| jq '.[] | {sid, phoneNumber, smsUrl, voiceUrl}'56{7"sid": "PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",8"phoneNumber": "+1209242XXXX",9"smsUrl": "https://very-secret.ngrok.io/sms",10"voiceUrl": "https://very-secret.ngrok.io/answer"11}12{13"sid": "PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",14"phoneNumber": "+1646887XXXX",15"smsUrl": "https://handler.twilio.com/twiml/EHxxxx",16"voiceUrl": "https://demo.twilio.com/welcome/voice/"17}18{19"sid": "PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",20"phoneNumber": "+1209337XXXX",21"smsUrl": "",22"voiceUrl": ""23}
The --properties
flag does not modify command output when combined with -o json
.
For example, twilio phone-numbers:list -o json --properties sid | jq .
will return the entire, unmodified JSON response, not an array of objects containing sid
.
To change the output format to tab separated values (TSV), add -o tsv
to a command.
This format is useful for loading information into spreadsheets, or for other machine processing. Like the default, columnar output format, you can use the --properties
option to specify which columns you would like included.
1$ twilio phone-numbers:list -o tsv2sid phoneNumber friendlyName3PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1209242XXXX SIP testing4PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1646887XXXX Congress hotline5PNxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +1209337XXXX DAVID'S SECRET CRUSH