Chilkat Online Tools

SQL Server / Cognite API v1 / Update 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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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": [
    --     {
    --       "id": 5332963297569946,
    --       "update": {
    --         "published": {
    --           "set": true
    --         },
    --         "rotation": {
    --           "set": [
    --             1420643.2340763807,
    --             61305313.21069074
    --           ]
    --         },
    --         "camera": {
    --           "set": {
    --             "target": [
    --               -94127719.41431686,
    --               -26125392.047989756
    --             ],
    --             "position": [
    --               -11778801.518837586,
    --               65784084.386047155
    --             ]
    --           }
    --         },
    --         "metadata": {
    --           "set": {}
    --         }
    --       }
    --     },
    --     {
    --       "id": 3037972078528582,
    --       "update": {
    --         "published": {
    --           "set": true
    --         },
    --         "rotation": {
    --           "set": [
    --             -79654794.7021859,
    --             -88865423.62704542
    --           ]
    --         },
    --         "camera": {
    --           "set": {
    --             "target": [
    --               75095534.65216562,
    --               -96489861.10036533
    --             ],
    --             "position": [
    --               77932146.41224226,
    --               85286604.61875996
    --             ]
    --           }
    --         },
    --         "metadata": {
    --           "set": {}
    --         }
    --       }
    --     }
    --   ]
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.published.set', 1
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.rotation.set[0]', '1420643.2340763807'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.rotation.set[1]', '61305313.21069074'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.camera.set.target[0]', '-94127719.41431686'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.camera.set.target[1]', '-26125392.047989756'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.camera.set.position[0]', '-11778801.518837586'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].update.camera.set.position[1]', '65784084.386047155'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[0].update.metadata.set'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.published.set', 1
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.rotation.set[0]', '-79654794.7021859'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.rotation.set[1]', '-88865423.62704542'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.camera.set.target[0]', '75095534.65216562'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.camera.set.target[1]', '-96489861.10036533'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.camera.set.position[0]', '77932146.41224226'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].update.camera.set.position[1]', '85286604.61875996'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[1].update.metadata.set'

    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/update', '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": [
        {
            "id": 5332963297569946,
            "update": {
                "published": {
                    "set": true
                },
                "rotation": {
                    "set": [
                        1420643.2340763807,
                        61305313.21069074
                    ]
                },
                "camera": {
                    "set": {
                        "target": [
                            -94127719.41431686,
                            -26125392.047989756
                        ],
                        "position": [
                            -11778801.518837586,
                            65784084.386047155
                        ]
                    }
                },
                "metadata": {
                    "set": {}
                }
            }
        },
        {
            "id": 3037972078528582,
            "update": {
                "published": {
                    "set": true
                },
                "rotation": {
                    "set": [
                        -79654794.7021859,
                        -88865423.62704542
                    ]
                },
                "camera": {
                    "set": {
                        "target": [
                            75095534.65216562,
                            -96489861.10036533
                        ],
                        "position": [
                            77932146.41224226,
                            85286604.61875996
                        ]
                    }
                },
                "metadata": {
                    "set": {}
                }
            }
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/3d/models/:modelId/revisions/update

Postman Collection Item JSON

{
  "id": "update3DRevisions",
  "name": "Update 3D revisions",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "3d",
        "models",
        ":modelId",
        "revisions",
        "update"
      ],
      "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            \"id\": 5332963297569946,\n            \"update\": {\n                \"published\": {\n                    \"set\": true\n                },\n                \"rotation\": {\n                    \"set\": [\n                        1420643.2340763807,\n                        61305313.21069074\n                    ]\n                },\n                \"camera\": {\n                    \"set\": {\n                        \"target\": [\n                            -94127719.41431686,\n                            -26125392.047989756\n                        ],\n                        \"position\": [\n                            -11778801.518837586,\n                            65784084.386047155\n                        ]\n                    }\n                },\n                \"metadata\": {\n                    \"set\": {}\n                }\n            }\n        },\n        {\n            \"id\": 3037972078528582,\n            \"update\": {\n                \"published\": {\n                    \"set\": true\n                },\n                \"rotation\": {\n                    \"set\": [\n                        -79654794.7021859,\n                        -88865423.62704542\n                    ]\n                },\n                \"camera\": {\n                    \"set\": {\n                        \"target\": [\n                            75095534.65216562,\n                            -96489861.10036533\n                        ],\n                        \"position\": [\n                            77932146.41224226,\n                            85286604.61875996\n                        ]\n                    }\n                },\n                \"metadata\": {\n                    \"set\": {}\n                }\n            }\n        }\n    ]\n}"
    }
  }
}