This is an advanced guide for automating connector creation. We highly recommend trying the Admin Dashboard or File Ingestion API first.
To see available connectors, see the Connectors page.

Guide

Skip to the Full Code section if you don’t want the step-by-step guide. In this example, we’ll automate creating Jira Connectors for a selection of projects. You will need an Admin API key to follow this guide.
1

Prepare your request

import requests

API_BASE_URL = "https://cloud.onyx.app/api"   # or your own domain
API_KEY = "YOUR_KEY_HERE"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}
2

Prepare your ConnectorSpecificConfig

Each Connector type has a different ConnectorSpecificConfig that is used to initialize the specific Connector class. To find the correct configuration, find your relevant Connector in backend/onyx/connectors/.For Jira, since we’re indexing a selection of projects, rather than all projects, we’ll need to specify jira_base_url, project_key, and optionally comment_email_blacklist.
JSON
{
  "jira_base_url": "string",
  "project_key": "string | null",
  "comment_email_blacklist": ["string"] | null
}
The ConnectorSpecificConfig are the same fields you fill out in the Admin Dashboard when creating a Connector.
3

Prepare your Connector payload

In addition to the ConnectorSpecificConfig, we also need to satisfy the schema for the ConnectorUpdateRequest object. See Core Concepts: Connectors for more details.In this example, we’ll set the access_type, name, source, input_type, refresh_freq, and prune_freq.
connector_payload = {
    "name": f"jira-{project_key}",
    "source": "jira",
    "input_type": "poll",
    "access_type": "PUBLIC",
    "connector_specific_config": {
        "jira_base_url": JIRA_BASE_URL,
        "project_key": project_key,
        "comment_email_blacklist": ["legal@company.com"]
    },
    "refresh_freq": 3600,  # Refresh every hour (3600 seconds)
    "prune_freq": 86400,   # Prune every day (86400 seconds)
}
4

Make the request

Save the Connector ID from the response! You will need this later.
import requests
import json
from datetime import datetime

PROJECTS_TO_INDEX = [
    "TECH",
    "SALES", 
    "OPS",
]

JIRA_BASE_URL = "https://your-company.atlassian.net"
connector_ids = []

for project_key in PROJECTS_TO_INDEX:
    connector_payload = {
        "name": f"jira-{project_key}",
        "source": "jira",
        "input_type": "poll",
        "access_type": "PUBLIC",
        "connector_specific_config": {
            "jira_base_url": JIRA_BASE_URL,
            "project_key": project_key,
            "comment_email_blacklist": ["legal@company.com"]
        },
        "refresh_freq": 3600,  # Refresh every hour (3600 seconds)
        "prune_freq": 86400,   # Prune every day (86400 seconds)
    }

    response = requests.post(
        f"{API_BASE_URL}/manage/admin/connector",
        headers=headers,
        json=connector_payload
    )

    if response.status_code == 200:
        connector_data = response.json()
        connector_id = connector_data.get('id')
        connector_ids.append(connector_id)
        print(f"Successfully created connector for project {project_key}")
        print(f"Connector ID: {connector_id}")
    else:
        print(f"Failed to create connector for project {project_key}")
        print(f"Status: {response.status_code}")
        print(f"Error: {response.text}")
5

Find your Credentials for the Connector

The easiest way to create a Credential is in the Admin Dashboard.
  • Click Add a Connector
  • Select your relevant Connector
  • Follow the instructions to create a Credential
Once your Credential is created, the Credential ID will be displayed to you.Certain Connectors may not require a Credential such as the File and Web connectors. credential_id: 0 is a default empty Credential you can use for these Connectors.To list your Credentials, you can use the GET manage/admin/credential endpoint.
response = requests.get(
    f"{API_BASE_URL}/manage/admin/credential",
    headers=headers
)

credentials = response.json()
jira_credential_id = next(cred for cred in credentials if cred['source'] == 'jira')['id']
6

Associate the Credential with the Connector

If you do not do this step, your Connector is not fully created and you will not see it in the Admin Dashboard!
for connector_id in connector_ids:
  try:
    response = requests.put(
      f"{API_BASE_URL}/manage/admin/connector/{connector_id}/credential/{jira_credential_id}",
      headers=headers,
    )

    if response.status_code == 200:
      print(f"Successfully associated credential with connector {connector_id}")
    else:
      print(f"Failed to associate credential with connector {connector_id}")
      print(f"Status: {response.status_code}. Error: {response.text}")
  except Exception as e:
    print(f"Failed to associate credential with connector {connector_id}: {e}")

Full Code

import requests
import json
from datetime import datetime

# Configuration
API_BASE_URL = "https://cloud.onyx.app/api"   # or your own domain
API_KEY = "YOUR_KEY_HERE"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Projects to create connectors for
PROJECTS_TO_INDEX = [
    "TECH",
    "SALES", 
    "OPS",
]

JIRA_BASE_URL = "https://your-company.atlassian.net"
connector_ids = []

# Step 1: Create connectors for each project
print("Creating connectors...")
for project_key in PROJECTS_TO_INDEX:
    connector_payload = {
        "name": f"jira-{project_key}",
        "source": "jira",
        "input_type": "poll",
        "access_type": "PUBLIC",
        "connector_specific_config": {
            "jira_base_url": JIRA_BASE_URL,
            "project_key": project_key,
            "comment_email_blacklist": ["legal@company.com"]
        },
        "refresh_freq": 3600,  # Refresh every hour (3600 seconds)
        "prune_freq": 86400,   # Prune every day (86400 seconds)
    }

    response = requests.post(
        f"{API_BASE_URL}/manage/admin/connector",
        headers=headers,
        json=connector_payload
    )

    if response.status_code == 200:
        connector_data = response.json()
        connector_id = connector_data.get('id')
        connector_ids.append(connector_id)
        print(f"Successfully created connector for project {project_key}")
        print(f"Connector ID: {connector_id}")
    else:
        print(f"Failed to create connector for project {project_key}")
        print(f"Status: {response.status_code}")
        print(f"Error: {response.text}")

# Step 2: Get credentials
print("\nFetching credentials...")
response = requests.get(
    f"{API_BASE_URL}/manage/admin/credential",
    headers=headers
)

if response.status_code == 200:
    credentials = response.json()
    # Find Jira credential (assumes you have one created)
    jira_credential = next((cred for cred in credentials if cred['source'] == 'jira'), None)
    
    if jira_credential:
        jira_credential_id = jira_credential['id']
        print(f"Found Jira credential with ID: {jira_credential_id}")
    else:
        print("No Jira credential found. Please create one in the Admin Dashboard first.")
        exit(1)
else:
    print(f"Failed to fetch credentials: {response.status_code}")
    print(f"Error: {response.text}")
    exit(1)

# Step 3: Associate credentials with connectors
print("\nAssociating credentials with connectors...")
for connector_id in connector_ids:
    try:
        response = requests.put(
            f"{API_BASE_URL}/manage/admin/connector/{connector_id}/credential/{jira_credential_id}",
            headers=headers,
        )

        if response.status_code == 200:
            print(f"Successfully associated credential with connector {connector_id}")
        else:
            print(f"Failed to associate credential with connector {connector_id}")
            print(f"Status: {response.status_code}. Error: {response.text}")
    except Exception as e:
        print(f"Failed to associate credential with connector {connector_id}: {e}")

print(f"\nCompleted! Created {len(connector_ids)} connectors with IDs: {connector_ids}")