Collaboration

Lock Project

Introduction

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.

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
required

Id of the project to edit.
codeSourceId string
required

Name of the environment that's creating the request.
Example
{
  "projectId": 0,
  "codeSourceId": "string"
}

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}")

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: