Chilkat Online Tools

SQL Server / Cognite API v1 / Update time series

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": [
    --     {
    --       "update": {
    --         "externalId": {
    --           "set": "in sint aliquip esse"
    --         },
    --         "name": {
    --           "setNull": true
    --         },
    --         "metadata": {
    --           "add": {},
    --           "remove": [
    --           ]
    --         },
    --         "unit": {
    --           "setNull": true
    --         },
    --         "assetId": {
    --           "setNull": true
    --         },
    --         "description": {
    --           "set": "officia nulla in"
    --         },
    --         "securityCategories": {
    --           "set": [
    --           ]
    --         },
    --         "dataSetId": {
    --           "set": 12304700
    --         }
    --       },
    --       "id": 8146739874146772
    --     },
    --     {
    --       "update": {
    --         "externalId": {
    --           "setNull": true
    --         },
    --         "name": {
    --           "set": "nisi proident voluptate non"
    --         },
    --         "metadata": {
    --           "add": {},
    --           "remove": [
    --           ]
    --         },
    --         "unit": {
    --           "setNull": true
    --         },
    --         "assetId": {
    --           "setNull": true
    --         },
    --         "description": {
    --           "set": "ullamco"
    --         },
    --         "securityCategories": {
    --           "set": [
    --           ]
    --         },
    --         "dataSetId": {
    --           "set": -60750056
    --         }
    --       },
    --       "externalId": "nisi nostrud"
    --     }
    --   ]
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].update.externalId.set', 'in sint aliquip esse'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.name.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[0].update.metadata.add'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[0].update.metadata.remove'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.unit.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].update.assetId.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].update.description.set', 'officia nulla in'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[0].update.securityCategories.set'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].update.dataSetId.set', 12304700
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.externalId.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].update.name.set', 'nisi proident voluptate non'
    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, 'UpdateBool', @success OUT, 'items[1].update.unit.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].update.assetId.setNull', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].update.description.set', 'ullamco'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'items[1].update.securityCategories.set'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].update.dataSetId.set', -60750056
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].externalId', 'nisi nostrud'

    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}}/timeseries/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": {
                "externalId": {
                    "set": "in sint aliquip esse"
                },
                "name": {
                    "setNull": true
                },
                "metadata": {
                    "add": {},
                    "remove": []
                },
                "unit": {
                    "setNull": true
                },
                "assetId": {
                    "setNull": true
                },
                "description": {
                    "set": "officia nulla in"
                },
                "securityCategories": {
                    "set": []
                },
                "dataSetId": {
                    "set": 12304700
                }
            },
            "id": 8146739874146772
        },
        {
            "update": {
                "externalId": {
                    "setNull": true
                },
                "name": {
                    "set": "nisi proident voluptate non"
                },
                "metadata": {
                    "add": {},
                    "remove": []
                },
                "unit": {
                    "setNull": true
                },
                "assetId": {
                    "setNull": true
                },
                "description": {
                    "set": "ullamco"
                },
                "securityCategories": {
                    "set": []
                },
                "dataSetId": {
                    "set": -60750056
                }
            },
            "externalId": "nisi nostrud"
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/timeseries/update

Postman Collection Item JSON

{
  "id": "alterTimeSeries",
  "name": "Update time series",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "timeseries",
        "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": "Updates one or more time series. Fields that are not included in the request, are not changed.\n\nFor primitive fields (String, Long Int), use 'set': 'value' to update the value; use 'setNull': true to set the field to null.\n\nFor JSON Array fields (for example securityCategories), use 'set': [value1, value2] to update the value; use 'add': [v1, v2] to add values; use 'remove': [v1, v2] to remove values.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"update\": {\n                \"externalId\": {\n                    \"set\": \"in sint aliquip esse\"\n                },\n                \"name\": {\n                    \"setNull\": true\n                },\n                \"metadata\": {\n                    \"add\": {},\n                    \"remove\": []\n                },\n                \"unit\": {\n                    \"setNull\": true\n                },\n                \"assetId\": {\n                    \"setNull\": true\n                },\n                \"description\": {\n                    \"set\": \"officia nulla in\"\n                },\n                \"securityCategories\": {\n                    \"set\": []\n                },\n                \"dataSetId\": {\n                    \"set\": 12304700\n                }\n            },\n            \"id\": 8146739874146772\n        },\n        {\n            \"update\": {\n                \"externalId\": {\n                    \"setNull\": true\n                },\n                \"name\": {\n                    \"set\": \"nisi proident voluptate non\"\n                },\n                \"metadata\": {\n                    \"add\": {},\n                    \"remove\": []\n                },\n                \"unit\": {\n                    \"setNull\": true\n                },\n                \"assetId\": {\n                    \"setNull\": true\n                },\n                \"description\": {\n                    \"set\": \"ullamco\"\n                },\n                \"securityCategories\": {\n                    \"set\": []\n                },\n                \"dataSetId\": {\n                    \"set\": -60750056\n                }\n            },\n            \"externalId\": \"nisi nostrud\"\n        }\n    ]\n}"
    }
  }
}