Collaboration
Lock Project
Request
The /projects/collaboration/lock/acquire API accepts requests in the following format:
LockCollaboratorRequest Model - Lock a project so you can edit it. This is necessary when the project has collaborators or when an LLM is editing files on your behalf via our MCP Server. | |
|---|---|
| projectId | integer Id of the project to edit. |
| codeSourceId | string Name of the environment that's creating the request. |
| Example |
{
"projectId": 23456789,
"codeSourceId": "MCP Server"
}
|
Responses
The /projects/collaboration/lock/acquire API provides a response in the following format:
200 Success
RestResponse Model - Base API response class for the QuantConnect API. | |
|---|---|
| success | boolean Indicate if the API request was successful. |
| errors | string Array List of errors with the API call. |
| Example |
{
"success": true,
"errors": [
"string"
]
}
|
401 Authentication Error
UnauthorizedError Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. | |
|---|---|
| www_authenticate | string Header |
Examples
The following example demonstates creating, reading, and deleting a project collaborator through the cloud API.
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'
# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'
def get_headers():
# Get timestamp
timestamp = f'{int(time())}'
time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')
# Get hased API token
hashed_token = sha256(time_stamped_token).hexdigest()
authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
authentication = b64encode(authentication).decode('ascii')
# Create headers dictionary.
return {
'Authorization': f'Basic {authentication}',
'Timestamp': timestamp
}
# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())
# --------------------
# The project ID of the project to manage its collaborator
project_id = 12345678
### Create Project Collaborator
# Define collaborator ID (replace with actual user ID)
collaborator_id = 'johnny_walker' # User ID from profile URL (e.g., https://www.quantconnect.com/u/johnny_walker)
# Send a POST request to the /projects/collaboration/create endpoint to add a collaborator
response = post(f'{BASE_URL}/projects/collaboration/create', headers=get_headers(), json={
"projectId": project_id, # ID of the project
"collaboratorUserId": collaborator_id, # ID of the user to add as collaborator
"collaborationLiveControl": True, # Grant live control permission
"collaborationWrite": True # Grant write permission
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the result
if result['success']:
print(f"Project Collaborator Created Successfully: {result}")
### Read Project Collaborator
# Send a POST request to the /projects/collaboration/read endpoint to get collaborators
response = post(f'{BASE_URL}/projects/collaboration/read', headers=get_headers(), json={
"projectId": project_id # ID of the project
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the collaborators
if result['success']:
print(f"Project Collaborators: {result}")
### Update Project Collaborator
# Send a POST request to the /projects/collaboration/update endpoint to update a collaborator's rights
response = post(f'{BASE_URL}/projects/collaboration/update', headers=get_headers(), json={
"projectId": project_id, # ID of the project
"collaboratorUserId": collaborator_id, # ID of the collaborator to update
"liveControl": True, # Grant live control permission
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the collaborators
if result['success']:
print(f"Project Collaborator Updated Successfully: {result}")
### Delete Project Collaborator
# Send a POST request to the /projects/collaboration/delete endpoint to remove collaborator
response = post(f'{BASE_URL}/projects/collaboration/delete', headers=get_headers(), json={
"projectId": project_id, # ID of the project
"collaboratorUserId": collaborator_id # ID of the collaborator to remove
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the result
if result['success']:
print(f"Project Collaborator Deleted Successfully: {result}")
if result['success']:
print(f"Project Collaborator Deleted Successfully: {result}")
The following example demonstrates how to add a collaborator to all projects that start with a given folder name.
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'
# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'
def get_headers():
# Get timestamp
timestamp = f'{int(time())}'
time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')
# Get hased API token
hashed_token = sha256(time_stamped_token).hexdigest()
authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
authentication = b64encode(authentication).decode('ascii')
# Create headers dictionary.
return {
'Authorization': f'Basic {authentication}',
'Timestamp': timestamp
}
# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())
# --------------------
# Define the folder prefix to match (e.g., "SubFolder/")
folder_prefix = "SubFolder/"
# Define collaborator ID (replace with actual user ID)
collaborator_id = 'johnny_walker'
# Send a POST request to the /projects/read endpoint to get all projects
response = post(f'{BASE_URL}/projects/read', headers=get_headers())
result = response.json()
if result['success']:
# Filter projects that start with the given folder prefix
matching_projects = [
project for project in result['projects']
if project['name'].startswith(folder_prefix)
]
# Add the collaborator to each matching project
for project in matching_projects:
response = post(f'{BASE_URL}/projects/collaboration/create', headers=get_headers(), json={
"projectId": project['projectId'],
"collaboratorUserId": collaborator_id,
"collaborationLiveControl": True,
"collaborationWrite": True
})
add_result = response.json()
if add_result['success']:
print(f"Added collaborator to project '{project['name']}' (ID: {project['projectId']})")
else:
print(f"Failed to add collaborator to project '{project['name']}': {add_result}")