Browse the docs

Send HTTP request

Sends an HTTP or HTTPS request and returns the status, headers and body.

Send method request to url

Details #

Sends one request and waits for the answer. method and url are required; the URL must start with http:// or https://.

The result is an object:

  • status: the status code, as a number.

  • headers: response headers, with lower-case names.

  • body: the response text.

  • json: the body parsed as JSON, present only when it parses.

That object is the step's output, and with into set it is stored in that variable, so {{res.status}} and {{res.json.name}} work in later steps. A reply with an error status such as 404 or 500 does not fail the step: check status with If. The step fails only when no answer arrives (no network, bad host, timeout).

Parameters #

ParameterTypeRequiredValuesWhat it does
methodone ofYesGET POST PUT PATCH DELETE HEADGET, POST, PUT, PATCH, DELETE or HEAD.
urltextYesSupports {{ }} values.
bodyany valueA string is sent as is. An object or array is sent as JSON, and Content-Type: application/json is added unless you set a content type yourself.
headersrecordAn object of header names and values.
impersonateone ofauto chrome safari nonechrome, safari or auto sends the request the way that browser would on the wire (its TLS handshake, header order and Accept-*). Left out, http is a plain API client.
intotextThe variable that receives the result object.
oauthtextThe name of an OAuth account (Library ▸ Sign-ins). The request goes with that account's access token as Authorization: Bearer …; the token is renewed when it is about to expire. Don't also set an Authorization header: the step fails. See Sign in to Google APIs.
sampleany valueWhat into holds during a dry run.
signIntextThe name of a saved sign-in (Library ▸ Sign-ins). Its cookies and user agent go with the request, only to the sites it was saved for; the profile follows the sign-in's browser. A reply that is a challenge page fails with challenge, and a signed-out sign-in with signInExpired.
timeoutnumberSeconds to wait. At least 1. Also settable on the step.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Post JSON to a webhook (sends a request)
Do
  1. Send POST to example.com/hook
Open in Switchboard to try it
Fetch a page and show the status (sends a request)
Do
  1. Send GET to example.com
  2. Show “Status {{res.status}}”
Open in Switchboard to try it
List your Tag Manager accounts as a Google account (sends a request)
Do
  1. Send GET to tagmanager.googleapis.com/tagmanager/v2/accounts
Open in Switchboard to try it

Gotchas #

  • OAuth scopes. An oauth account can only do what its scopes allow; a missing scope comes back as a 403 reply (not a failure). Tick the scope in Library ▸ Sign-ins and sign in again. A Google app whose consent screen is still in Testing has refresh tokens that expire after 7 days: publish the consent screen (In production) to keep the sign-in. A 401 reply does not fail the step; a refresh the provider rejects does, with "sign in to … again".

  • Dry run. No request is sent. into gets sample (or an empty string), so give a sample shaped like a real answer if later steps read res.status or res.json.

  • Timeout. The step is cancelled after 10 s by default. A slow API needs timeout. On timeout the step fails with "timed out".

  • Large bodies. The variable holds the whole body. The trace keeps only the first 32 KB of it (and drops json), so a long reply looks cut off in Activity but is complete in into.

  • No cookies or cache. Each request is independent. There is no session and no stored login between steps. Send what the server needs in headers.

  • Redirects are followed automatically.

See also #

Run shell script, If, Set variable, Sign in to Google APIs