Skip to content
apigent extract

apigent extract

Test extraction rules against a sample response. No request is sent.

Synopsis

apigent extract [flags] VAR=METHOD:EXPR [VAR=METHOD:EXPR...]

apigent extract reads a response body from --file or stdin and prints what each rule extracts. Use it to get a rule right before saving it on a request with apigent save --extract or apigent edit --extract.

Rules have the form VAR=METHOD:EXPR:

MethodExpressionExample
jsonpathJSONPath, including array indexesorderId=jsonpath:$.data.items[0].id
jqAlias of jsonpathid=jq:$.id
headerResponse header name (pass headers with -H)loc=header:Location
regexRegular expression; the first capture group is the valuen=regex:"amount":(\d+)

JSONPath extraction keeps large numbers exact (1000000, not 1e+06).

Flags

FlagShortDefaultDescription
--file-fstdinResponse body file
--header-HnoneResponse header 'Key: Value' for header rules (repeatable)

Examples

JSONPath from stdin

echo '{"data":{"id":"ord_1"}}' | apigent extract 'orderId=jsonpath:$.data.id'
orderId = ord_1

Several rules against a file

apigent extract -f resp.json -H 'Location: /orders/9' \
  'loc=header:Location' \
  'first=jsonpath:$.data.items[0].id' \
  'n=regex:"amount":(\d+)'

Save the rule once it works

apigent edit "create-order" --extract 'orderId=jsonpath:$.data.id'

Related commands