Skip to content

HTTP (get, post & delete) commands

Kenneth Auchenberg edited this page Oct 31, 2019 · 2 revisions

The CLI has three commands that let you interact with the Stripe API in test mode. You can easily make GET, POST, and DELETE commands with the Stripe CLI.

For example, you can retrieve a specific charge:

$ stripe get /charges/ch_123

You can also pass data in using the -d flag:

$ stripe post /charges -d amount=100 -d source=tok_visa -d currency=usd

These commands support many of the features on the Stripe API (e.g. selecting a version, pagination, and expansion) through command-line flags, so you won't need to provide specific headers. For a full list of supported flags, see the wiki page.

You can pipe the output of these commands to other tools. For example, you could use jq to extract information from JSON the API returns, and then use that information to trigger other API requests.

Here’s a simple example that lists past_due subscriptions, extracts the IDs, and cancels those subscriptions:

$ stripe get /subscriptions -d status=past_due | jq ".data[].id" | xargs -I % -p stripe delete /subscriptions/%

Advanced options

The get, post, and delete commands expose simple interface to make raw requests against the Stripe API. They allow you to get, update, and delete existing data without having to use curl.

The commands provide a few usage shortcuts:

  • if you provide an id, the CLI will know how to load that directly
  • paths provided do not require `/v1/ to be prepended to every request

For example:

$ stripe get ch_1EOA8IByst5pquEteSXgXjj0
{
  "id": "ch_1EOA8IByst5pquEteSXgXjj0",
  "object": "charge",
  "amount": 1099,
  "amount_refunded": 0,
  ...
}

The commands also map all of our top-level API features such as expand and paging:

Command Flag Description Example
get, post, delete -d, --data Data to pass for the API request --data id=cust_123abc
get, post, delete -e, --expand Response attributes to expand inline. Available on all API requests, see the documentation for specific objects that support expansion --expand customer,charges
get, post, delete -i, --idempotency Sets the idempotency key for your request, preventing replaying the same requests within a 24 hour period. --idempotency foobar123456
get, post, delete -v, --api-version Set the Stripe API version to use for your request --api-version 2019-03-14
get, post, delete --stripe-account Set a header identifying the connected account for which the request is being made --stripe-account m_1234acbd
get, post, delete -s, --show-headers Show headers on responses to GET, POST, and DELETE requests --show-headers
delete -c, --confirm Automatically confirm the command being entered. WARNING: This will result in NOT being prompted for confirmation for certain commands --confirm
get -l, --limit A limit on the number of objects to be returned, between 1 and 100 (default is 10) --limit 50
get -a, --starting-after Retrieve the next page in the list. This is a cursor for pagination and should be an object ID --starting-after cust_1234abc
get -b, --ending-before Retrieve the previous page in the list. This is a cursor for pagination and should be an object ID --ending-before cust_1234abc