Articles in this section

request( options )

request( options ) makes an HTTP request to the integrator.io API from inside a script. Use it to reach endpoints that have no dedicated runtime object, or when you need direct control over the method, headers, query string, or body of the call.

This article documents the function's argument, return value, and error behavior. For resource-specific methods such as exports.run() or flows.get(), see integrator.io API and JavaScript runtime objects.

Argument

options <Object> — Contains the following properties:

  • method <String> — The HTTP method to use. Default: GET.
  • relativeURI <String, required> — The URI relative to api.integrator.io. For example, v1/connections.
  • qs <Object> — Query string key-value pairs to append to relativeURI.
  • headers <Object> — Key-value pairs to append to the HTTP headers.
  • body <Object> — The HTTP request body.

Returns

<Object> — The response object contains the following properties:

  • statusCode <Number> — The HTTP status code.
  • headers <Object> — All HTTP response headers. Access a single header with headers.headerName, where headerName is case-insensitive, or call headers() to return them all.
  • body <Object> — The HTTP response body.

Exceptions

This function throws an error only when the HTTP request can't be completed — for example, when the options argument is invalid, or when the request times out because the remote server took too long to respond or the response took too long to transmit.

4xx and 5xx responses don't throw an error. The status code is passed through in the response object, so check statusCode to detect them:

let resp = request({ method: 'GET', relativeURI: 'v1/connections' })

if (resp.statusCode >= 400) {
  // handle the error
}

Example

let resp = request({
  method: 'GET',
  relativeURI: 'v1/connections',
  qs: {
    'admin': 'true'
  },
  headers: {
    'X-Requested-With': 'XMLHttpRequest'
  },
  body: { }
})