Javascript SDK

Basics

Table of contents

Installation

Node.js

The preferred way of installing the Flex.io Javascript SDK is to use NPM (Node.js Package Manager). Simply go to your project’s directory and enter the following command at the command prompt:

Source code

The source code for the Flex.io Javascript SDK is available on GitHub. You can download or view it here.

Setup

You can generate an API by signing in to Flex.io

Collections

Connections

Listing connections

Deleting one or more connections

Pipes

Listing pipes

Deleting one or more pipes

Connections

Using custom headers

Bearer token authentication

Basic authentication

OAuth2 authentication

Pipes

Conversion

Dead-simple CSV to JSON conversion in two lines of code

Execute

Run some basic Javascript code

Simple input/output with Javascript jobs

Request

GET request with no parameters

GET request with parameters

GET request shorthand with no parameters

GET request shorthand with parameters

GET request using a connection

POST request with headers and data

Render

Render a webpage with shorthand parameters (defaults to PNG)

Render a webpage to PDF with shorthand parameters

Render a webpage to PNG with extended params

Render a webpage to PDF with extended params

Reference

Flexio.setup()

Flexio.setup(apiKey, [options])

This function allows you to supply your API key to the SDK library. You can generate an API key from the Flex.io dashboard after you sign in.

Example:

Flexio.connections.create()

Flexio.connections.create(conn, callback(err))

Creates a new connection object. The connection object specified in the parameter conn can either be a plain object with the desired key/value pairs set or alternativily a Flexio.connection object.

Example 1:

Example 2:

Flexio.connections.load()

Flexio.connections.load(identifier, callback(err, conn))

Loads a connection object. Once the load operation has completed, the callback function will be invoked.

Flexio.connections.list()

Flexio.connections.list(callback)

Retrieve a list of connections available to the user. Upon completion of the call, an array of connection info objects will be returned via the callback function.

Example:

Flexio.pipes.load()

Flexio.pipes.load(identifier, callback(err,pipe))

Loads a pipe object. Once the load operation has completed, the callback function will be invoked.

Flexio.pipes.list()

Flexio.pipes.list(callback(err,pipe))

Retrieve a list of pipes available to the user. Upon completion of the call, an array of pipes will be returned via the callback function.

Example:

Flexio.pipes.run()

Flexio.pipes.run([pipeIdentifier|pipeObject|taskArray])

Flexio.pipes.run([pipeIdentifier|pipeObject|taskArray], callback)

Flexio.pipes.run([pipeIdentifier|pipeObject|taskArray], {params}, callback)

Calling this method will cause a pipe to run. The pipe is specified by the first parameter, and can be a pipe identifier (such as a pipe id or pipe alias) or a pipe object created with Flexio.pipe() or retrieved by Flexio.pipes.load(). The caller can also specify an array of javascript objects specifying the raw task parameters for pipe execution.

Additional parameters, such as query string parameters (so-called ‘GET parameters’), or form parameters and files may be specified in the optional params object.

When the pipe has finished executing, the callback function will be invoked if one has been specified. The spec for the callback function is

The response object has several properties used to retrieve the response payload. response.text is used to get a text payload. response.data is used to get a JSON object payload. The raw binary payload, which is used for images and other binary data, can be directly accessed via response.buffer, and in an ArrayBuffer object. In a web browser client setting, a Blob object can be accessed via response.blob.

Flexio.pipe.run()

Flexio.pipe.run()

Flexio.pipe.run(callback(err,response))

Flexio.pipe.run({params}, callback(err,response)))

These functions are convenience functions that invoke the functionality of Flexio.pipes.run(), which is documented above.

Example:

Flexio.pipe.echo()

Flexio.pipe.execute()

Flexio.pipe.javascript()

Flexio.pipe.javascript(javascriptFunction)

Flexio.pipe.javascript(javascriptCodeString)

pipe.javascript() adds a Javascript execute step to the pipe. If a function is specified, it is automatically used as the flexio_handler function. If Javascript code is specified in a string, the code must include a callback handler which will be invoked upon execution:

Example 1:

Example 2:

Flexio.pipe.render()

Flexio.pipe.render(params)

pipe.render() renders a web page to an image or PDF file. By default, a PNG image of the webpage is generated. An optional params argument can be specified with various options that modify the behavior of the rendering process. Here are a list of the options that can be specified on the params object:

Option Description
format The file format to generate (possible values are ‘jpeg’, ‘pdf’, or ‘png’). Defaults to ‘png’
full A boolean true/false indicating whether the full webpage from top to bottom should be rendered. Defaults to false.
height The height of the resulting image. If full is specified, this argument is ignored. Defaults to 600
scrollbars A boolean true/false indicating whether or not scrollbars are included in the rendered image. Defaults to false.
paper When rendering a PDF, this option specifies the paper size to use. (Possible values ‘A4, ‘Letter’, etc.) Defaults to ‘Letter’
url The URL to navigate to
width The width of the resulting image. If full is specified, this argument is ignored. Defaults to 800

Example:

Flexio.pipe.python()

Flexio.pipe.python(pythonCodeString)

pipe.python() adds a Python execute step to the pipe. The code for the script is passed as a string parameter to the function.

Example: