Chilkat Online Tools

SQL Server / Cognite API v1 / Update sequences

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": [
    --     {
    --       "update": {
    --         "name": {
    --           "set": "commodo consectetur labore adipisicing et"
    --         },
    --         "description": {
    --           "set": "minim do officia commodo enim"
    --         },
    --         "assetId": {
    --           "setNull": true
    --         },
    --         "externalId": {
    --           "setNull": true
    --         },
    --         "metadata": {
    --           "set": {}
    --         },
    --         "dataSetId": {
    --           "setNull": false
    --         },
    --         "columns": {
    --           "modify": [
    --           ],
    --           "add": [
    --           ],
    --           "remove": [
    --           ]
    --         }
    --       },
    --       "id": 2341818327837744
    --     },
    --     {
    --       "update": {
    --         "name": {
    --           "setNull": true
    --         },
    --         "description": {
    --           "setNull": false
    --         },
    --         "assetId": {
    --           "setNull": false
    --         },
    --         "externalId": {
    --           "set": "ea non cupidatat"
    --         },
    --         "metadata": {
    --           "add": {},
    --           "remove": [
    --           ]
    --         },
    --         "dataSetId": {
    --           "set": -97287500
    --         },
    --         "columns": {
    --           "modify": [
    --           ],
    --           "add": [
    --           ],
    --           "remove": [
    --           ]
    --         }
    --       },
    --       "externalId": "do"
    --     }
    --   ]
    -- }

    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, 'UpdateString', @success OUT, 'items[0].update.name.set', 'commodo consectetur labore adipisicing et'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].update.description.set', 'minim do officia commodo enim'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.assetId.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.externalId.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[0].update.metadata.set'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.dataSetId.setNull', 0
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[0].update.columns.modify'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[0].update.columns.add'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[0].update.columns.remove'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.name.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.description.setNull', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.assetId.setNull', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].update.externalId.set', 'ea non cupidatat'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[1].update.metadata.add'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[1].update.metadata.remove'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].update.dataSetId.set', -97287500
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[1].update.columns.modify'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[1].update.columns.add'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[1].update.columns.remove'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].externalId', 'do'

    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}}/sequences/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": [
        {
            "update": {
                "name": {
                    "set": "commodo consectetur labore adipisicing et"
                },
                "description": {
                    "set": "minim do officia commodo enim"
                },
                "assetId": {
                    "setNull": true
                },
                "externalId": {
                    "setNull": true
                },
                "metadata": {
                    "set": {}
                },
                "dataSetId": {
                    "setNull": false
                },
                "columns": {
                    "modify": [],
                    "add": [],
                    "remove": []
                }
            },
            "id": 2341818327837744
        },
        {
            "update": {
                "name": {
                    "setNull": true
                },
                "description": {
                    "setNull": false
                },
                "assetId": {
                    "setNull": false
                },
                "externalId": {
                    "set": "ea non cupidatat"
                },
                "metadata": {
                    "add": {},
                    "remove": []
                },
                "dataSetId": {
                    "set": -97287500
                },
                "columns": {
                    "modify": [],
                    "add": [],
                    "remove": []
                }
            },
            "externalId": "do"
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/sequences/update

Postman Collection Item JSON

{
  "id": "updateSequences",
  "name": "Update sequences",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "sequences",
        "update"
      ],
      "query": [
      ],
      "variable": [
      ]
    },
    "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"
      }
    ],
    "description": "Update one or more sequences. Fields that are not included in the request, are not changed.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"update\": {\n                \"name\": {\n                    \"set\": \"commodo consectetur labore adipisicing et\"\n                },\n                \"description\": {\n                    \"set\": \"minim do officia commodo enim\"\n                },\n                \"assetId\": {\n                    \"setNull\": true\n                },\n                \"externalId\": {\n                    \"setNull\": true\n                },\n                \"metadata\": {\n                    \"set\": {}\n                },\n                \"dataSetId\": {\n                    \"setNull\": false\n                },\n                \"columns\": {\n                    \"modify\": [],\n                    \"add\": [],\n                    \"remove\": []\n                }\n            },\n            \"id\": 2341818327837744\n        },\n        {\n            \"update\": {\n                \"name\": {\n                    \"setNull\": true\n                },\n                \"description\": {\n                    \"setNull\": false\n                },\n                \"assetId\": {\n                    \"setNull\": false\n                },\n                \"externalId\": {\n                    \"set\": \"ea non cupidatat\"\n                },\n                \"metadata\": {\n                    \"add\": {},\n                    \"remove\": []\n                },\n                \"dataSetId\": {\n                    \"set\": -97287500\n                },\n                \"columns\": {\n                    \"modify\": [],\n                    \"add\": [],\n                    \"remove\": []\n                }\n            },\n            \"externalId\": \"do\"\n        }\n    ]\n}"
    }
  }
}