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
Copy
Ask AI
import requestsAPI_BASE_URL = "https://cloud.onyx.app/api" # or your own domainAPI_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. 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.
The ConnectorSpecificConfig are the same fields you fill out in the Admin Panel 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.
The easiest way to create a Credential is in the Admin Panel.
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.
Copy
Ask AI
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 Panel!
Copy
Ask AI
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}")