Chilkat Online Tools

Node.js / Cognite API v1 / Create 3D revisions

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "items": [
    //     {
    //       "fileId": 61515356,
    //       "published": false,
    //       "rotation": [
    //         -53019239.474532664,
    //         -93390044.04179798
    //       ],
    //       "metadata": {},
    //       "camera": {
    //         "target": [
    //           37611347.255532116,
    //           3250125.148054078
    //         ],
    //         "position": [
    //           -52657505.10953469,
    //           12877141.765109628
    //         ]
    //       }
    //     },
    //     {
    //       "fileId": -78327169,
    //       "published": false,
    //       "rotation": [
    //         68722196.8050077,
    //         -2333724.1439721733
    //       ],
    //       "metadata": {},
    //       "camera": {
    //         "target": [
    //           90393811.40333363,
    //           -2389888.4961474687
    //         ],
    //         "position": [
    //           49903616.60856527,
    //           10849620.22958082
    //         ]
    //       }
    //     }
    //   ]
    // }

    var json = new chilkat.JsonObject();
    json.UpdateInt("items[0].fileId",61515356);
    json.UpdateBool("items[0].published",false);
    json.UpdateNumber("items[0].rotation[0]","-53019239.474532664");
    json.UpdateNumber("items[0].rotation[1]","-93390044.04179798");
    json.UpdateNewObject("items[0].metadata");
    json.UpdateNumber("items[0].camera.target[0]","37611347.255532116");
    json.UpdateNumber("items[0].camera.target[1]","3250125.148054078");
    json.UpdateNumber("items[0].camera.position[0]","-52657505.10953469");
    json.UpdateNumber("items[0].camera.position[1]","12877141.765109628");
    json.UpdateInt("items[1].fileId",-78327169);
    json.UpdateBool("items[1].published",false);
    json.UpdateNumber("items[1].rotation[0]","68722196.8050077");
    json.UpdateNumber("items[1].rotation[1]","-2333724.1439721733");
    json.UpdateNewObject("items[1].metadata");
    json.UpdateNumber("items[1].camera.target[0]","90393811.40333363");
    json.UpdateNumber("items[1].camera.target[1]","-2389888.4961474687");
    json.UpdateNumber("items[1].camera.position[0]","49903616.60856527");
    json.UpdateNumber("items[1].camera.position[1]","10849620.22958082");

    http.SetRequestHeader("content-type","application/json");
    http.SetRequestHeader("api-key","{{api-key}}");

    // resp: HttpResponse
    var resp = http.PostJson3("https://domain.com/api/v1/projects/{{project}}/3d/models/:modelId/revisions","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "items": [
        {
            "fileId": 61515356,
            "published": false,
            "rotation": [
                -53019239.474532664,
                -93390044.04179798
            ],
            "metadata": {},
            "camera": {
                "target": [
                    37611347.255532116,
                    3250125.148054078
                ],
                "position": [
                    -52657505.10953469,
                    12877141.765109628
                ]
            }
        },
        {
            "fileId": -78327169,
            "published": false,
            "rotation": [
                68722196.8050077,
                -2333724.1439721733
            ],
            "metadata": {},
            "camera": {
                "target": [
                    90393811.40333363,
                    -2389888.4961474687
                ],
                "position": [
                    49903616.60856527,
                    10849620.22958082
                ]
            }
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/3d/models/:modelId/revisions

Postman Collection Item JSON

{
  "id": "create3DRevisions",
  "name": "Create 3D revisions",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "3d",
        "models",
        ":modelId",
        "revisions"
      ],
      "query": [
      ],
      "variable": [
        {
          "key": "modelId",
          "description": "Model ID.",
          "disabled": true,
          "type": "number"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "api-key",
        "value": "{{api-key}}",
        "description": "An admin can create API keys in the Cognite console."
      },
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"fileId\": 61515356,\n            \"published\": false,\n            \"rotation\": [\n                -53019239.474532664,\n                -93390044.04179798\n            ],\n            \"metadata\": {},\n            \"camera\": {\n                \"target\": [\n                    37611347.255532116,\n                    3250125.148054078\n                ],\n                \"position\": [\n                    -52657505.10953469,\n                    12877141.765109628\n                ]\n            }\n        },\n        {\n            \"fileId\": -78327169,\n            \"published\": false,\n            \"rotation\": [\n                68722196.8050077,\n                -2333724.1439721733\n            ],\n            \"metadata\": {},\n            \"camera\": {\n                \"target\": [\n                    90393811.40333363,\n                    -2389888.4961474687\n                ],\n                \"position\": [\n                    49903616.60856527,\n                    10849620.22958082\n                ]\n            }\n        }\n    ]\n}"
    }
  }
}