We’re still yet to update much of our docs, but the type hinting will help you out, if you’re using vscode, make sure you have the python extension enabled.
However, client.commit.create should continue to work, Are you seeing it return an error?
You may need to do some work to adjust your code to pass or fetch model ids rather than branch names. This is the main difference with the new api schema
Thanks! Yes, I’m just working on how to pass the “main” name for the modelId (branch) for the input, as strings are not allowed.
The other problem I’m facing is the ServerTransport. It has stream_id in the arguments… Maybe I’ll manage it, or is there also better way for transport?
So, I think my confusion is comming because the client.commit.create method is not compatible with the new host app.speckle.server anymore.
And I mixed the methods, so now I’m getting 401 error: Failed to create a new version: 401 Client Error: Unauthorized for url
Hi,
There’s a couple things I noticed about the code you’ve shared.
1: Properly fetching the model id
The above line is incorrect. project.get_with_models returns a project. so .id will be the project’s id, not the model id.
Have a look at the typing of the return type (ProjectWithModels) and its parent Project class to see all of the properties available.
You’ll need to do something like this if you want the model id.
project = client.project.get_with_models(project_id)
# Gets the first model on the project
model = project.models.items[0]
# OR, if you want to specifically get a model named "main"
model = next(m for m in project.models.items if m.name == "main")
model_id = model.id
The property warnings does not exist, likely is confusing the error message you’re seeing. CreateVersionInput requires only objectId, modelId, and projectId.
Here is a sample code that I’ve tested. If you follow give this, you should find you have no problems
from specklepy.api.client import SpeckleClient
from specklepy.api.resources.current.version_resource import CreateVersionInput
MY_TOKEN = "XXXX" # Replace this with your token. It will need atleast "streams:read" and "streams:write" scopes
PROJECT_ID = "c1faab5c62" # Replace this with your project id.
OBJECT_ID = "321ebe2adb13f8ac79f6903d20813e5f" # Replace this with your object Id, this object id needs to already have been sent to the project
BRANCH_NAME = "main"
client = SpeckleClient()
client.authenticate_with_token(MY_TOKEN)
project = client.project.get_with_models(PROJECT_ID)
model = next(m for m in project.models.items if m.name == BRANCH_NAME)
input_data = CreateVersionInput(
objectId=OBJECT_ID,
modelId=model.id,
projectId=project.id,
message="what ever your message is here!",
)
new_version_id = client.version.create(input_data)