> ## Documentation Index
> Fetch the complete documentation index at: https://docs.suprsend.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bigquery

> Guide to set up BigQuery database connection to auto sync subscriber lists.

With this integration, you can directly send notifications on your 360 degree data sitting in your data warehouse. This enables your data teams or product managers to automate user syncing, setup recurring user cohort sync and create [subscriber lists](/docs/lists) on SuprSend. You can then trigger notification to this list using our [broadcast](/docs/broadcast) API.

## Getting started

To start syncing data from your BigQuery database, you need to add this integration on the connector page.

1. Go to [SuprSend dashboard -> Settings -> Connectors](https://app.suprsend.com/en/staging/connectors) page. Here, you'll see the list of available connectors. If you have already setup any connectors in the past, you'll see a list of existing connectors. Click on **`+New Connector`** button to add the connector.

2. Click on BigQuery and add below information:

   * **Name**: A name to uniquely qualify the connection as you'll see it in the connector list on your sync task. You can add the name of database here for easy identification.

   * **Service account key json**: Steps to generate this are mentioned in the next section.

<Frame>
  <img src="https://mintcdn.com/suprsend/3ix_OjxB_ZGM-pa-/images/docs/151c7dd-image.png?fit=max&auto=format&n=3ix_OjxB_ZGM-pa-&q=85&s=e2124ea414407052120fa2993a4a2d5c" width="1972" height="980" data-path="images/docs/151c7dd-image.png" />
</Frame>

### Step-1: Generating OAuth client key and secret

<Steps>
  <Step title="Selecting OAuth client ID">
    Go to the [Credentials](https://console.cloud.google.com/apis/credentials) page in the Google Cloud Platform console and click on **"+Create Credentials"**. Select OAuth client ID from the options list.

    <Frame>
      <img src="https://files.readme.io/cc6d2c3-Screenshot_2022-11-23_at_6.15.28_PM.png" />
    </Frame>
  </Step>

  <Step title="OAuth consent screen">
    If you have not created OAuth consent screen before, you will need to create one.

    <Frame>
      <img src="https://files.readme.io/ca30516-Screenshot_2022-11-23_at_6.17.34_PM.png" />
    </Frame>
  </Step>

  <Step title="Use Internal option from the list">
    Since SuprSend will be used for your internal employees only, Use `Internal` option from the list

    <Frame>
      <img src="https://files.readme.io/719d9d2-Screenshot_2022-11-23_at_6.18.48_PM.png" />
    </Frame>
  </Step>

  <Step title="Provide below details">
    Enter required details like App name, your email, developer contact information, authorized domain etc.

    <Frame>
      <img src="https://files.readme.io/fd1f40b-Screenshot_2022-11-23_at_6.28.58_PM.png" />
    </Frame>
  </Step>
</Steps>

### Step-2: Granting permissions

SuprSend requires you to grant certain user permissions on your BigQuery warehouse to successfully access data from it. Perform the below three steps in the exact order to grant these permissions:

<Steps>
  <Step title="Creating a role and granting permissions">
    1.1. Go to the [Roles](https://console.cloud.google.com/iam-admin/roles) section of Google Cloud platform dashboard and click on **CREATE ROLE**.

    <Frame>
      <img src="https://files.readme.io/1593c56-image.png" />
    </Frame>

    1.2. Fill in the details as shown

    <Frame>
      <img src="https://files.readme.io/f4c596c-Bifrost_role.jpg" />
    </Frame>

    1.3. Click on **ADD PERMISSIONS** and add the following permissions

    > bigquery.datasets.get
    > bigquery.jobs.create
    > bigquery.jobs.list
    > bigquery.tables.get
    > bigquery.tables.getData
    > bigquery.tables.list

    1.4. Finally, click on **CREATE**.
  </Step>

  <Step title="Creating a service account and attaching a role to it">
    2.1. Go to [Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) and select the project which has the dataset or the table that you want to use and Click on CREATE SERVICE ACCOUNT

    <Frame>
      <img src="https://files.readme.io/5fd5659-image.png" />
    </Frame>

    2.2. Fill in the Service Account details as shown below, and click on CREATE AND CONTINUE:

    <Frame>
      <img src="https://files.readme.io/f032300-Screenshot_2022-11-29_at_11.11.49_AM.png" />
    </Frame>

    2.3. Fill in the Role details as shown below, and click on CONTINUE:

    <Frame>
      <img src="https://files.readme.io/14c0317-Screenshot_2022-11-29_at_11.13.18_AM.png" />
    </Frame>

    2.4. Click on DONE to move to the list of service accounts.
  </Step>

  <Step title="Creating and downloading the JSON key">
    3.1. Click on the three dots icon under Actions in the service account that you just created and select **Manage keys**, as shown:

    <Frame>
      <img src="https://files.readme.io/772b9a7-Screenshot_2022-11-29_at_11.16.39_AM.png" />
    </Frame>

    3.2. Click on **ADD KEY**, followed by Create new key, as shown:

    <Frame>
      <img src="https://files.readme.io/84ae3e5-Screenshot_2022-11-29_at_11.18.37_AM.png" />
    </Frame>

    3.3. Select **JSON** and click on **CREATE**

    <Frame>
      <img src="https://files.readme.io/19d6cdb-Screenshot_2022-11-29_at_11.19.04_AM.png" />
    </Frame>

    3.4. A JSON file will be downloaded on your system. This file is required in your database integration form.
  </Step>
</Steps>

## Best Practices

Before you setup your database sync, you should take some measures to ensure the security of your customers’ data and limit performance impacts to your backend database. The following “best practice” suggestions can help you limit the potential for data exposure and minimize performance impacts:

* **Sync your read-only replica instance:** Do not sync data directly from your main instance. Instead use a read-only data replica to minimize the load and avoid data loss on your main database.
* **User connected here should have minimal privileges:** You should have a database user with minimal privileges. This person only requires read permissions with access limited to the tables you want to sync from.
* **Sync only the data that you’ll need:** Limiting your query can improve performance, and minimize the potential to expose sensitive data. Select only the columns you need to either update user profile in SuprSend and to create list sync.
* **"Use `{{last_sync_time}}` to limit query results:** Make sure you use the **`{{last_sync_time}}`** variable in your recurring sync queries. It stores the timestamp of last successful sync in your list. Adding it in your where statement against datetime index can really speed up the query and limit the number of results returned in consecutive syncs. `{{last_sync_time}}` is stored in timestamp format. Use relevant cast expression to format it based on your column type.
* **Limit your sync frequency:** Setup a sync frequency based on how frequently you want to send notifications on that list. If the previous sync is still in progress when the next interval occurs, we’ll skip the operation and catch up your data on the next interval. Skipped syncs show`Ignored`status in the logs. Frequently skipped operations may indicate that you’re syncing too often. You should monitor your first few syncs to ensure that you haven’t impacted your system’s performance.

***
