Rutter Link
The Basics
Rutter Link is the client-side component that your users will interact with in order to link their accounts to Rutter and allow you to access their accounts via the Rutter API.
Rutter Link will handle credential validation, OAuth, and error handling for each platform that we support. Link works across all modern browsers and platforms, including web, iOS, Android, and mobile webviews.
Example Rutter Link flow with QuickBooks Online
Option 1: Create a Link URL via Dashboard
For testing, we recommend using our built-in Rutter Link URL generation. This will allow you to quickly go through the authentication flow and connect a platform.
- Navigate to the connections page.
- Click “Create a Connection”
- Copy “Shareable URL” and open it in a new tab or window. This will open a Rutter Link Flow.
Option 2: Create a Link URL programmatically
Creating Rutter Link URLs can be done programmatically via the Create a Connection Endpoint. There are two ways to use this API:
- Create a connection that allows the merchant to select which platform they want to connect. This is done by leaving the request body empty.
- Create a connection with existing credentials. This is done by specifying the platform and including the associated credentials (OAuth, Basic Auth, etc.) for the connection. Rutter will use these fields to make the authenticated API requests to the platform.
For more information, see our documention.
Option 3: Integrate Link in your web app
On web instances React & Javascript, loading the Rutter JS will create a global Rutter
object on the window
object. To open the Merchant Auth flow, you must call Rutter.create()
while passing in your public_key
, and then open()
on the resulting object.
Create
The create
function takes in an object as an argument. Below is an example:
1const rutterInstance = Rutter.create({
2 publicKey: "YOUR_RUTTER_PUBLIC_KEY",
3 onSuccess: function (publicToken) {
4 // Send publicToken to your backend and exchange
5 console.log("public token: " + publicToken)
6 },
7 onError: function (error) {
8 console.error(error)
9 }
10})
After the Rutter Instance is created, the resulting object has the following functions:
Open
The open
function opens the Merchant Auth popup, and will return a publicToken
after a successful authentication to the callback you specified in the create
function above. Below is an example:
1// Assuming rutterInstance has already been created as shown above
2
3// Opens the Rutter popup
4rutterInstance.open()
5
6// Opens the Rutter popup directly to the Shopify Auth Step
7rutterInstance.open({
8 platform: "SHOPIFY"
9})
Troubleshooting
You should set your Cross-Origin-Opener-Policy policy to be same-origin-allow-popups
or Rutter Link will fail to communicate with your application. The reason for this is that Rutter Link uses the window.postMessage()
method to communicate between the popup and the parent window.
You can use the debug
mode to see what's going on under the hood. To enable debug mode, set the debug
property to true
when creating instantiating Rutter Link.
Token Exchange
Rutter makes it easy for you to obtain and manage tokens from Rutter Link. A public_token
is returned whenever a merchant successfully shares their data with you. However, the public_token
cannot be used directly with our API, it must be exchanged for an access_token
through our Token Exchange endpoint.
Token Exchange Flow
- Merchant authorizes you to use their data via Rutter Link.
- Link returns a
public_token
on the frontend, which must be exchanged for anaccess_token
. - Exchange the
public_token
for anaccess_token
by calling/item/public_token/exchange
.
The access_token
can then be used to call Rutter endpoints and obtain information about a Connection.
Configuration
JavaScript and React bindings take in a configuration object with the following format:
Field | Type | Notes |
---|---|---|
publicKey | string | Your Rutter-issued public token which you can find in the Rutter Dashboard. |
onSuccess | function of following type: (publicToken?: string) => any; | The publicToken query parameter is the public token of a Rutter Connection. You will need to exchange this for an access_token to use the API. |
onExit | function of following type: (err?: ErrorEnum) => any; | See definition for ErrorEnum below |
debug | boolean | Whether to enable debug mode, which log the steps of the Rutter Link flow to the console. Defaults to false. |
A Note on Callbacks
Only one callback will be called - either onSuccess or onExit, but not both.
ErrorEnum
Value | Conditions to Trigger |
---|---|
"MERCHANT_CLOSED" | The popup window has been closed prematurely (usually by the user) - i.e. authentication is incomplete but window is closed. |
"UNKNOWN_ERROR" | The window has passed an event to the link bindings which cannot be handled. |