Connect to Webflow Data in JRuby
JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Webflow makes it easy to integrate connectivity to live Webflow data in JRuby. This article shows how to create a simple JRuby app that connects to Webflow data, executes a query, and displays the results.
Configure a JDBC Connection to Webflow Data
Before creating the app, note the installation location for the JAR file for the JDBC Driver (typically C:\Program Files\CData\CData JDBC Driver for Webflow\lib).
JRuby natively supports JDBC, so you can easily connect to Webflow and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.
Authentication
Webflow uses OAuth 2.0 authentication to ensure secure access to sites, CMS collections, e-commerce data, and other resources. This authentication method allows you to securely connect to your Webflow workspace and manage resources with proper authorization.
OAuth 2.0 Setup and Configuration
Step 1: Create a Webflow OAuth Application
To set up OAuth authentication:
- Visit the Webflow Developer Portal
- Navigate to "Apps & Integrations" in your Webflow account
- Click "Register an App" to create a new OAuth application
- Configure the application name, description, and redirect URI (CallbackURL)
- Copy the Client ID and Client Secret for use in your connection
Required Connection Properties
- AuthScheme: Set this to OAuth (required)
- OAuthClientId: Client ID from your Webflow OAuth application (required)
- OAuthClientSecret: Client secret from your Webflow OAuth application (required)
- CallbackURL: Redirect URI specified in your OAuth application (required)
- InitiateOAuth: Set to GETANDREFRESH for automatic token management (recommended)
Required OAuth Scopes
The Webflow API Profile requires the following OAuth scopes:
- sites:read - Read access to site information and configuration
- pages:read - Read access to site pages
- cms:read - Read access to CMS collections and items
- forms:read - Read access to forms and form submissions
- assets:read - Read access to media assets and folders
- ecommerce:read - Read access to products, orders, and inventory
- authorized_user:read - Read access to the authorized user
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Webflow JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.api.jar
Fill in the connection properties and copy the connection string to the clipboard.
Below is a typical JDBC connection string for Webflow:
jdbc:api:Profile=C:\profiles\Webflow.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackUrl=your_callback_url;
Create a JRuby App with Connectivity to Webflow Data
Create a new Ruby file (for example: APISelect.rb) and open it in a text editor. Copy the following code into your file:
require 'java'
require 'rubygems'
require 'C:/Program Files/CData/CData JDBC Driver for Webflow 2018/lib/cdata.jdbc.api.jar'
url = "jdbc:api:Profile=C:\profiles\Webflow.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackUrl=your_callback_url;"
conn = java.sql.DriverManager.getConnection(url)
stmt = conn.createStatement
rs = stmt.executeQuery("SELECT , FROM Sites")
while (rs.next) do
puts rs.getString(1) + ' ' + rs.getString(2)
end
With the file completed, you are ready to display your Webflow data with JRuby. To do so, simply run your file from the command line:
jruby -S APISelect.rb
Writing SQL-92 queries to Webflow allows you to quickly and easily incorporate Webflow data into your own JRuby applications. Download a free trial today!