Chilkat Online Tools

SQL Server / Cognite API v1 / Create 3D revisions

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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
    --         ]
    --       }
    --     }
    --   ]
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].fileId', 61515356
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].published', 0
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].rotation[0]', '-53019239.474532664'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].rotation[1]', '-93390044.04179798'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[0].metadata'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].camera.target[0]', '37611347.255532116'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].camera.target[1]', '3250125.148054078'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].camera.position[0]', '-52657505.10953469'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].camera.position[1]', '12877141.765109628'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].fileId', -78327169
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].published', 0
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].rotation[0]', '68722196.8050077'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].rotation[1]', '-2333724.1439721733'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[1].metadata'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].camera.target[0]', '90393811.40333363'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].camera.target[1]', '-2389888.4961474687'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].camera.position[0]', '49903616.60856527'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].camera.position[1]', '10849620.22958082'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'api-key', '{{api-key}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/projects/{{project}}/3d/models/:modelId/revisions', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

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