Create Connection Flow for OAuth2.0 using the Rivery API

Introduction & Summary

The recent introduction of new endpoints to the Rivery API has opened up a new host of programmatic workflows developers can take advantage of. In this community article, we explore the programmatic creation of connections using OAuth2.0 in a rivery account and the use cases that this flow enables.

In this workflow, using the curl command line tool we make a series of calls to retrieve an auth_uri link for a data source that can be opened in a browser, authorized by the user (via OAuth2.0) and it’s credentials saved in a connection in the Rivery account UI. In summary the workflow is as followed:

  1. Create a Rivery API token in your Rivery account.
  2. Get list of all connection types (GET Connection Types List)
  3. Make a new credentials request (OAuth2 New Credentials Request)
  4. Send the auth_uri link to the user for authentication.
  5. Wait for the user/client to authorize the source.
  6. Once authorized, retrieve the credentials that the user inputted (OAuth2 GET Credentials)
  7. Provide the credentials obtained in the response into a PUT request (Create New Connection)
  8. Update connection (PUT Update Connection by ID) - send in whole connection body, with changed parameter


1. Create a new API token in your Rivery account.

Under the “API Tokens” tab in the Rivery console, click “Add Token”. Give it a name and assign the scopes as shown below:

Keep the access_token in a safe place once the token is created. You will NOT be able to view this access token again after the screen.

2. Get the list of all available connection types using GET Connection Types List.

This will provide you with a list of datasource_id’s that you can use in the next step.

3. Execute the OAuth2 New Credentials Request.

Ensure that you provide the correct string datasource_id for the source type that you wish to add. In making this and all subsequent API calls, make sure you use the access token created in step(1). In the subsequent example calls and responses, we are using the datasource_id for the google sheets connection (gspreadsheet) to create the connection. Note that the auth_uri link retrieved from the response to this call will only be valid for the duration of the validity_duration parameter specified in the call.

List of example datasource_id’s.

Example call:

curl -d ‘{“datasource_id”: “gspreadsheet”,“validity_duration”: 1300}’ -H “Content-Type: application/json” -X POST -H “Authorization: Bearer <access_token>”

Example Response (200):


“pull_id”: “eyJhbGciOiJIUzI1NiIsImV4cCI6MTYwOTE5MjA2NCwiaWF0IjoxNjA5MTkxNzY0fQ.eyJwdWxsX2lkIjoiNWZlYTUxNTRmNTY4MmM3ZWJlZGExMWU2IiwiYXBwbGljYXRpb25faWQiOm51bGx9._wbqCDbGUKj9t0BD6YIp2ZsB_70pT9ipXSs1B0x1oT0”,

“auth_uri”: ""


4. Send the auth_uri to the user/client that you wish to create the connection for.

Get the auth_uri and pull_id from the response to step (3). Let the client open the auth_uri in an external browser.

5. Let the client complete the OAuth2.0 authorization process to the desired source connection that you are adding.

Let the user complete this (possibly over a zoom call). The authorization is successful once the client sees a JSON with the key value “Connected = True” in their browser.

6. Request the OAuth2 GET Credentials endpoint.

Use the pull_id and the auth_uri retrieved in step (3).

Example call:

curl -d ‘{“pull_id”: “eyJhbGciOiJIUzI1NiIsImV4cCI6MTYwOTE5MzQ5NSwiaWF0IjoxNjA5MTkyMTk1fQ.eyJwdWxsX2lkIjoiNWZlYTUzMDNmNTY4MmM3ZWJlZGExMWVkIiwiYXBwbGljYXRpb25faWQiOm51bGx9.pKKugMOj3Mre9nM56Cyc6tmvVQAAc465gP0BuFktboA”, “auth_uri”: “Sign in - Google Accounts”}’ -H “Content-Type: application/json” -X POST -H “Authorization: Bearer <access_token>”

Example response (200):


“application_id”: null, “access_token”: “ya29.a0AfH6SMDtW7FFrML65NAx_0z76vMv_zbhN1IecKHbnWs9Ds2qf-3zauscenmPwUmSKGhO35uBjgO-pB-BjLriMqvOfYG6Mkm_2KDwnkHVujR3PKVFIeSqZTivzPYul_MUgm2khfEK8wRfsvUD0kcn7ECq6s4geGo86q9IUy91FJiQ”, “status_code”: 200, “expires_in”: 3599, “token_type”: “Bearer”, “client_id”: “”, “scope”: “”, “message”: “Connected to Google”, “refresh_token”: “1//04C1r8Heg6ZpICgYIARAAGAQSNwF-L9Ir1WOesC4znfkZ5bpcTlVsJ78Zd4d7lJtmvmbxtYYuvMhkpBrPAdrNmquFDZMxQ6tVRsg”


7. Make a Create New Connection request.

Replace the “credentials” key in the payload with the full response retrieved in step (6). In this step you can also set the name of the connection in the connection_name parameter as it will appear in the “Connections” tab in the Rivery UI.

Example call:

curl -d ‘{“connection_type”: “gspreadsheet”,“connection_name”: “google sheets Connection (OAuth2 Connection)”,“credentials”: {“application_id”: null, “access_token”: “ya29.a0AfH6SMDtW7FFrML65NAx_0z76vMv_zbhN1IecKHbnWs9Ds2qf-3zauscenmPwUmSKGhO35uBjgO-pB-BjLriMqvOYG6Mkm_2KDwnkHVujR3PKVFIeSqZTivzPYul_MUgm2khfEK8wRfsvUD0kcn7ECq6s4geGo86q9IUy91FJiQ”, “status_code”: 200, “expires_in”: 3599, “token_type”: “Bearer”, “client_id”: “”, “scope”: “”, “message”: “Connected to Google”, “refresh_token”: “1//04C1r8Heg6ZpICgYIARAAGAQSNwF-L9Ir1WOesC4znfkZ5bpcTlVsJ78Zd4d7lJtmvmbxtYYuvMhkpBrPAdrNmquFDZMxQ6tVRsg”}}’ -H “Content-Type: application/json” -X PUT -H “Authorization: Bearer <access_token>”

Example response (200):

{“cross_id”: “5fea567ff5682c7ebeda11f1”, “status_code”: 200, “message”: “connection saved”, “_id”: “5fea567ff5682c7ebeda11f1”, “connection_name”: “google sheets Connection (OAuth2 Connection)”}

If the response comes back as 200, the connection has been created in your Rivery account and you can find it under the “Connections” tab.


This workflow helps enable several user cases that could be beneficial to your organization.

  1. Enabling a single Rivery Account to manage connections for multiple clients that are using the same sources.
  2. Creating a partition between the client and the Rivery platform to divide business operations, and data pipeline RND.
  3. Allowing for a Rivery account to serve as a service provider for ELT development and testing across a range of environments, connections, and users.
1 Like