Skip to content
Request Actions

Request Actions

Real API flows depend on earlier responses: you log in to get a token, create a resource to get its id, then use them in the next request. The Actions tab of HTTP and gRPC requests automates this without code. For anything more involved, use a Python script.

The tab has three sections:

SectionRunsOptions
BeforeBefore the request is sentNone, Trigger request, Python
AfterAfter the response arrivesNone, Set environment, Python
ExtractAfter the response arrivesAny number of extraction rules

Values that actions write go into the active environment and are saved to it, so the next request can use them as {{name}}. With No Environment selected there is nowhere to write them, and Set environment and Extract do nothing.

Before: trigger another request

Choose Trigger request and pick a request from the list. Every time you send this request, Chapar first sends the one you picked, runs its own actions, and then sends this one.

Trigger a request first

A typical use is a Get todo request whose URL is {{baseUrl}}/todos/{{todoId}}, triggering Create todo, which extracts todoId from its response. Sending Get todo creates a fresh todo and then fetches it.

If the triggered request fails, or one of its post-request actions fails, this request is not sent and the error is shown.

After: set an environment variable

Choose Set environment to copy one value from the response into the environment:

FieldMeaning
Env keyThe variable to set, for example lastUpdated.
Status codeOnly set it when the response has this status, for example 200. For gRPC use the status code number (0 is OK).
FromHTTP: Body, Header or Cookie. gRPC: Body, Metadata or Trailers.
JSON Path / Header / KeyFor the body, a JSONPath such as $.data.updated_at. Otherwise the header, cookie, metadata or trailer name.

After you send the request once, a Preview line shows the value the action would set from the last response.

Set an environment variable

Extract: several values at once

Extract holds a table of rules, so one response can fill several variables. Click Add for each rule:

ColumnMeaning
CheckboxTurns the rule on or off.
TargetThe environment variable to set.
Frombody, header or cookies for HTTP; body, metadata or trailers for gRPC.
StatusOnly apply the rule for this status code. Leave it empty to apply it to any status.
Path/KeyA JSONPath for body, or the header, cookie, metadata or trailer name.
PreviewThe value the rule found in the last response.

Extract a value from the body

Rules that read a header and the body, from the same response:

Extract from a header and the body

If a rule fails, for example because its path doesn’t match, the other rules still run, and the response shows which rule and path failed.

Extract rules run together with None or Set environment in After. When After is a Python script, do the extraction in the script with chapar.env.set(...).

JSONPath cheat sheet

PathSelects
$.tokenThe token field of the top-level object
$.data.idid inside data
$.data[0].idid of the first item of the data array
$.data.user.emailA nested field
Set environment and Extract store text values only. If the path selects a number, a boolean, an object or an array, nothing is stored. Use a Python script for those: chapar.env.set("count", response.json()["total"]) stores any value, as text or JSON.

Where to see what happened

Open the response’s Timeline tab. The Pre-request and Post-request steps show what ran, how long it took, and any error.

When to use a script instead

Use a Python script when you need to compute a value (a signature, a timestamp, a hash), change the request before it is sent, skip a request, set several values with logic, or check the response with tests.