Chilkat Online Tools

DataFlex / Cognite API v1 / Update time series

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "items[0].update.externalId.set" "in sint aliquip esse" To iSuccess
    Get ComUpdateBool Of hoJson "items[0].update.name.setNull" True To iSuccess
    Get ComUpdateNewObject Of hoJson "items[0].update.metadata.add" To iSuccess
    Get ComUpdateNewArray Of hoJson "items[0].update.metadata.remove" To iSuccess
    Get ComUpdateBool Of hoJson "items[0].update.unit.setNull" True To iSuccess
    Get ComUpdateBool Of hoJson "items[0].update.assetId.setNull" True To iSuccess
    Get ComUpdateString Of hoJson "items[0].update.description.set" "officia nulla in" To iSuccess
    Get ComUpdateNewArray Of hoJson "items[0].update.securityCategories.set" To iSuccess
    Get ComUpdateInt Of hoJson "items[0].update.dataSetId.set" 12304700 To iSuccess
    Get ComUpdateInt Of hoJson "items[0].id" 123 To iSuccess
    Get ComUpdateBool Of hoJson "items[1].update.externalId.setNull" True To iSuccess
    Get ComUpdateString Of hoJson "items[1].update.name.set" "nisi proident voluptate non" To iSuccess
    Get ComUpdateNewObject Of hoJson "items[1].update.metadata.add" To iSuccess
    Get ComUpdateNewArray Of hoJson "items[1].update.metadata.remove" To iSuccess
    Get ComUpdateBool Of hoJson "items[1].update.unit.setNull" True To iSuccess
    Get ComUpdateBool Of hoJson "items[1].update.assetId.setNull" True To iSuccess
    Get ComUpdateString Of hoJson "items[1].update.description.set" "ullamco" To iSuccess
    Get ComUpdateNewArray Of hoJson "items[1].update.securityCategories.set" To iSuccess
    Get ComUpdateInt Of hoJson "items[1].update.dataSetId.set" -60750056 To iSuccess
    Get ComUpdateString Of hoJson "items[1].externalId" "nisi nostrud" To iSuccess

    Send ComSetRequestHeader To hoHttp "content-type" "application/json"
    Send ComSetRequestHeader To hoHttp "api-key" "{{api-key}}"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://domain.com/api/v1/projects/{{project}}/timeseries/update" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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