Skip to Content
Docs
pay CLI

Call the API

Run any API operation from a terminal or a script.

Every API operation has a command named after its resource and action. Successes print the API's JSON to standard output, on one line with --raw, and errors print the API's error JSON to standard error. When a retry hid an earlier failure, lines about that failure follow the JSON. Amounts are integers in minor units (for example, --amount 2000 is $20.00 USD).

Terminal

pay charges create --amount 2000 --currency usd --source pm_card_685125127054035968
pay charges retrieve chrg_685125114794084352
pay refunds list --limit 10

pay --help lists the resources, pay charges --help a resource's commands, and pay charges create --help a command's arguments and fields.

Parameters

Pass endpoint parameters as positional arguments, flags, key-value pairs, or raw JSON.

  • Path parameters are arguments, in the path's order.
  • Query parameters and body fields are flags, with dashes for dots and underscores. For example, created.greater_than is --created-greater-than. Pass object values as JSON strings (for example, --metadata '{"order_id":"6735"}').
  • -d key=value sets any field, and dots nest. A value that's valid JSON is sent as JSON, so quote a number that must be a string.
  • --data-json passes the full request body inline, from a file with @, or from standard input with -. Explicit flags override fields set in --data-json.

Terminal

pay charges create --data-json '{"amount":2000,"currency":"usd"}' --source pm_card_685125127054035968
pay charges create --amount 2000 --currency usd --source pm_card_685125127054035968 -d 'metadata.order_id="6735"'

Every command that takes an idempotency key sends a new one. To send your own, use --idempotency-key.

Retries

A command retries twice by default, and --max-retries changes that. --max-retries 0 turns retries off.

Every PUT and PATCH is retried only after a 429, or when it never connected. If one of these requests receives no response, check whether it succeeded before running it again. --timeout bounds each attempt, one minute by default.

Page through lists

--all reads every page and prints the items as one JSON array, for cursor lists and page lists alike. --limit-total stops after that many items, and --limit is the size of each page.

Terminal

pay charges list --all --limit 100 --customer-reference-id cust_ext_abc123
pay value-lists list --all --limit-total 50

Files

The upload's type comes from the file's extension, or --content-type.

Terminal

pay documents create --filename receipt.pdf --reference order-6735 --content-type application/pdf --content-length 102400
pay documents upload doc_296645958265997322 --file ./receipt.pdf
pay documents retrieve-contents doc_296645958265997322 --output document.pdf

--content-length must be the file's exact size. See Upload and download files.

Raw requests

pay get, post, put, patch, and delete take any path under /v1. -d builds the query for get and the body for the others. A full URL is refused and redirects aren't followed, so your key only goes to the API. To upload a file, use pay documents upload.

Terminal

pay get /charges -d limit=3
pay post /refunds -d charge=chrg_685125114794084352 -d amount_to_refund=500
pay patch /charges/chrg_685125114794084352 -d description="Order 6735"
Was this page helpful?