Skip to main content

Upload 3D models programmatically

From the Cognite Console, you can upload a single 3D model to Cognite Data Fusion (CDF) without writing any code. This article explains how you can upload several 3D models using the Cognite API and SDKs, for instance, for nightly updates.

Prerequisites

To upload 3D models, you need a service account with an API key with the threed:write capability for your CDF project. See Manage access for services to learn more.

You also need:

  • Your CDF project name. You will use this as the [projectname] below.
  • The file name(s) of the model(s) you will be uploading. You will use this as the [filename] below.

Upload 3D models

To upload 3D models using Cognite API and SDKs:

  1. Create a model that can hold several revisions:

    curl -H "api-key: $COGNITE_API_KEY" -H "Content-type: application/json" -X POST "https://api.cognitedata.com/api/v1/projects/[projectname]/3d/models" -d '{"items": [{"name":"model name"}]}'

    API reference: /api#tag/3D-Models/operation/create3DModels

  2. Copy and make a note of the id field in the response. You will use this as the [modelId] below.

  3. Create a file placeholder to make the file available for processing later.

    curl -H "api-key: $COGNITE_API_KEY" -H "Content-type: application/json" -X POST "https://api.cognitedata.com/api/v1/projects/[projectname]/files" -d '{"name":"[filename]"}'

    API reference: /api#tag/Files/operation/initFileUpload

  4. Copy and make a note of the id field in the response. You will use this as the [fileId] below. Also, copy and make a note of uploadUrl. You will use this as the [uploadUrl] below.

  5. Upload the file.

    curl --upload-file [filename] [uploadUrl]

    Google API reference: https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#example_uploading_the_file

  6. Create a versioned model and link the file from the first step to the revision. This also starts the processing of the model.

    curl -H "api-key: $COGNITE_API_KEY" -H "Content-type: application/json" -X POST "https://api.cognitedata.com/api/v1/projects/[projectname]/3d/models/[modelId]/revisions" -d '{"items": [{"fileId":"[fileId]"}]}'

    API reference: /api#tag/3D-Model-Revisions/operation/create3DRevisions

  7. Monitor the processing of the model.

    API reference: /api#tag/3D-Model-Revisions/operation/get3DRevision