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

# Set up connection environments with the API

> Configure dev and prod connection environments with the API.

export const categoryIcons = {
  'administration': 'lock',
  'api': 'terminal',
  'connections': 'database',
  'dashboards': 'table-columns',
  'embed': 'code',
  'errors': 'exclamation',
  'modeling': 'wrench',
  'patterns': 'plus',
  'schedules & alerts': 'envelope',
  'visualizations': 'chart-column',
  'workbooks': 'book'
};

export const GuideSidebar = ({category, relatedLinks, updatedDate}) => {
  const [progress, setProgress] = React.useState(0);
  React.useEffect(() => {
    const sidebar = document.querySelector('.guide-sidebar');
    if (!sidebar) return;
    let container = sidebar.parentElement;
    while (container && !container.querySelector('.guide-header')) {
      container = container.parentElement;
    }
    if (container && !container.classList.contains('guide-page-layout')) {
      container.classList.add('guide-page-layout');
    }
  }, []);
  React.useEffect(() => {
    const handleScroll = () => {
      const scrollTop = window.scrollY;
      const docHeight = document.documentElement.scrollHeight - window.innerHeight;
      const scrollPercent = docHeight > 0 ? scrollTop / docHeight * 100 : 0;
      setProgress(Math.min(100, Math.max(0, scrollPercent)));
    };
    window.addEventListener('scroll', handleScroll, {
      passive: true
    });
    handleScroll();
    return () => window.removeEventListener('scroll', handleScroll);
  }, []);
  const icon = category ? categoryIcons[category.toLowerCase()] || 'book' : 'book';
  return <aside className="guide-sidebar">
      <div className="guide-sidebar-content">
        <a href="/guides" className="guide-sidebar-back">
          <Icon icon="arrow-left" iconType="solid" size={14} />
          <span>All guides</span>
        </a>

        <div className="guide-sidebar-section">
          <div className="guide-sidebar-label">Progress</div>
          <div className="guide-sidebar-progress">
            <div className="guide-mascot">
              <svg viewBox="0 0 450 450" width="48" height="48">
                <defs>
                  <clipPath id="progressClip">
                    <rect x="0" y={450 - progress * 4.5} width="450" height={progress * 4.5} />
                  </clipPath>
                  <linearGradient id="blobbyGradient" x1="55.9753" y1="0" x2="492.197" y2="169.724" gradientUnits="userSpaceOnUse">
                    <stop stopColor="#BCA2F3" />
                    <stop offset="0.572917" stopColor="#FF7AA2" />
                    <stop offset="1" stopColor="#F3D4A2" />
                  </linearGradient>
                </defs>

                {}
                <circle cx="223.901" cy="223.901" r="213.901" transform="matrix(-0.999988 -0.0049013 0.00491945 -0.999988 447.797 449.992)" fill="#FAFAFA" stroke="#480B38" strokeWidth="20" />

                {}
                <circle cx="223.901" cy="223.901" r="213.901" transform="matrix(-0.999988 -0.0049013 0.00491945 -0.999988 447.797 449.992)" fill="url(#blobbyGradient)" stroke="#480B38" strokeWidth="20" clipPath="url(#progressClip)" />

                {}
                <path d="M310.41 195.084C310.41 200.052 301.362 212.472 284.328 212.472C266.585 212.472 258.246 201.294 258.246 195.912" stroke="#480B38" strokeWidth="17.3883" strokeMiterlimit="1.33344" strokeLinecap="round" />
                <circle cx="21.168" cy="21.168" r="21.168" transform="matrix(-1 0 0 1 388.658 169.001)" fill="#480B38" />
                <circle cx="21.168" cy="21.168" r="21.168" transform="matrix(-1 0 0 1 223.467 169.001)" fill="#480B38" />
              </svg>
            </div>
            <span className="guide-sidebar-progress-text">{Math.round(progress)}%</span>
          </div>
        </div>

        {category && <div className="guide-sidebar-section">
            <div className="guide-sidebar-label">Category</div>
            <div className="guide-sidebar-category">
              <Icon icon={icon} iconType="solid" size={14} />
              <span>{category}</span>
            </div>
          </div>}

        {updatedDate && <div className="guide-sidebar-section">
            <div className="guide-sidebar-label">Last updated</div>
            <div className="guide-sidebar-date">{updatedDate}</div>
          </div>}

        {relatedLinks && relatedLinks.length > 0 && <div className="guide-sidebar-section">
            <div className="guide-sidebar-label">Related</div>
            <ul className="guide-sidebar-links">
              {relatedLinks.map((link, index) => <li key={index}>
                  <a href={link.href}>{link.title}</a>
                </li>)}
            </ul>
          </div>}
      </div>
    </aside>;
};

export const GuideTitle = ({title}) => {
  return <div className="guide-header">
      <h1 className="guide-title">{title}</h1>
    </div>;
};

<GuideSidebar categoryIcons={categoryIcons} category="api" updatedDate="January 2026" />

<GuideTitle title="Set up connection environments with the API" />

Connection environments allow you to configure multiple database connections based on [user attributes](/administration/users/attributes). This is useful for scenarios where you need to provide different database access based on user roles or environments.

In this guide, we'll walk you through creating development and production connection environments.

## Requirements

To follow the steps in this guide, you'll need:

* An [Omni API key](/api/authentication)
* **Connection Admin** permissions on an existing Omni database connection

## Steps

<Steps>
  <Step title="Create the base connection">
    This is the default connection that will be used when no user attribute matches an environment connection. Use the [Create a connection API](/api/connections/create-connection) to create the connection.

    In this example, this would be a connection to your **development** database:

    ```bash title="POST /api/v1/connections" theme={null}
    curl -L -X POST 'https://blobsrus.omniapp.co/api/v1/connections' \
    -H 'Authorization: Bearer <TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
      "dialect": "postgres",
      "name": "Postgres (Development)",
      "host": "postgres-dev.my-org.com",
      "port": 5432,
      "database": "dev",
      "username": "dbuser",
      "passwordUnencrypted": "mypassword",
      "includeSchemas": "public",
      "queryTimeoutSeconds": 900
    }'
    ```
  </Step>

  <Step title="Create environment connections">
    Environment conditions are additional connections with the same dialect as the base connection. Use the [Create a connection API](/api/connections/create-connection) to create the connection(s).

    In this example, this would be a connection to your **production** database:

    ```bash title="POST /api/v1/connections" theme={null}
    curl -L -X POST 'https://blobsrus.omniapp.co/api/v1/connections' \
    -H 'Authorization: Bearer <TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
      "dialect": "postgres",
      "name": "Postgres (Production)",
      "host": "postgres-prod.my-org.com",
      "port": 5432,
      "database": "prod",
      "username": "dbuser",
      "passwordUnencrypted": "mypassword",
      "includeSchemas": "public",
      "queryTimeoutSeconds": 900
    }'
    ```
  </Step>

  <Step title="Connect the base and environment connections">
    Use the [Create connection environments API](/api/connection-environments/create-connection-environments) to associate the base connection with the environment connections. Provide the following:

    * `baseConnectionId` - The ID of the base connection. In this example, that's your **development** database.
    * `environmentConnectionIds` - The ID(s) of the connection environments. In this example, that's your **production** database.

    ```json title="POST /api/v1/connection-environments" theme={null}
    curl -L -X POST 'https://blobsrus.omniapp.co/api/v1/connection-environments' \
    -H 'Authorization: Bearer <TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
      "baseConnectionId": "c0f12353-4817-4398-bcc0-d501e6dd2f64",
      "environmentConnectionIds": "b31f9c9f-208d-48a2-9ae3-ff80f2c79fed"
    }'
    ```
  </Step>

  <Step title="Configure the base connection user attribute">
    Use the [Update a connection API](/api/connections/update-connection) to specify which user attribute will be used to determine the connection environment.

    In this example, configure the base connection to use the `environment` user attribute and set its default value to `dev`:

    ```json title="PATCH /api/v1/connections/:id" theme={null}
    curl -L -X PATCH 'https://blobsrus.omniapp.co/api/v1/connections/c0f12353-4817-4398-bcc0-d501e6dd2f64' \
    -H 'Authorization: Bearer <TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
      "userAttributeNameForConnectionEnvironments": "environment",
      "userAttributeValuesForDefaultEnvironment": "dev"
    }'
    ```
  </Step>

  <Step title="Define user attribute values for environments">
    Use the [Update connection environment user attributes API](/api/connection-environments/update-connection-environment) to specify which user attribute values will trigger the use of each environment connection.

    In this example, set the user attribute values for the **production** environment connection to `prod`:

    ```json title="PUT /api/v1/connection-environments/:id" theme={null}
    curl -L -X PUT 'https://blobsrus.omniapp.co/api/v1/connection-environments/b31f9c9f-208d-48a2-9ae3-ff80f2c79fed' \
    -H 'Authorization: Bearer <TOKEN>' \
    -H 'Content-Type: application/json' \
    -d '{
      "userAttributeValues": "prod"
    }'
    ```

    Now, users with the `environment` attribute set to `prod` will use the production database, while users with the `environment` attribute set to `dev` (or any other value not associated with an environment connection) will use the development database.
  </Step>
</Steps>
