Chilkat Online Tools

unicodeC / Cognite API v1 / Update relationships

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // 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": [
    //     {
    //       "externalId": "dolor amet sit",
    //       "update": {
    //         "sourceType": {
    //           "set": "timeSeries"
    //         },
    //         "sourceExternalId": {
    //           "set": "qui labor"
    //         },
    //         "targetType": {
    //           "set": "file"
    //         },
    //         "targetExternalId": {
    //           "set": "laborum"
    //         },
    //         "confidence": {
    //           "setNull": true
    //         },
    //         "startTime": {
    //           "set": 97867670
    //         },
    //         "endTime": {
    //           "setNull": true
    //         },
    //         "dataSetId": {
    //           "set": 8379377116294748
    //         },
    //         "labels": {
    //           "set": [
    //             {
    //               "externalId": "ullamco anim"
    //             },
    //             {
    //               "externalId": "aliquip ut"
    //             }
    //           ]
    //         }
    //       }
    //     },
    //     {
    //       "externalId": "reprehenderit ut",
    //       "update": {
    //         "sourceType": {
    //           "set": "timeSeries"
    //         },
    //         "sourceExternalId": {
    //           "set": "adipisicing ullamco consequat"
    //         },
    //         "targetType": {
    //           "set": "sequence"
    //         },
    //         "targetExternalId": {
    //           "set": "aliqua"
    //         },
    //         "confidence": {
    //           "setNull": true
    //         },
    //         "startTime": {
    //           "setNull": false
    //         },
    //         "endTime": {
    //           "set": 51106464
    //         },
    //         "dataSetId": {
    //           "setNull": false
    //         },
    //         "labels": {
    //           "set": [
    //             {
    //               "externalId": "Lorem ipsum"
    //             },
    //             {
    //               "externalId": "officia consectetur pariatur"
    //             }
    //           ]
    //         }
    //       }
    //     }
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"items[0].externalId",L"dolor amet sit");
    CkJsonObjectW_UpdateString(json,L"items[0].update.sourceType.set",L"timeSeries");
    CkJsonObjectW_UpdateString(json,L"items[0].update.sourceExternalId.set",L"qui labor");
    CkJsonObjectW_UpdateString(json,L"items[0].update.targetType.set",L"file");
    CkJsonObjectW_UpdateString(json,L"items[0].update.targetExternalId.set",L"laborum");
    CkJsonObjectW_UpdateBool(json,L"items[0].update.confidence.setNull",TRUE);
    CkJsonObjectW_UpdateInt(json,L"items[0].update.startTime.set",97867670);
    CkJsonObjectW_UpdateBool(json,L"items[0].update.endTime.setNull",TRUE);
    CkJsonObjectW_UpdateInt(json,L"items[0].update.dataSetId.set",123);
    CkJsonObjectW_UpdateString(json,L"items[0].update.labels.set[0].externalId",L"ullamco anim");
    CkJsonObjectW_UpdateString(json,L"items[0].update.labels.set[1].externalId",L"aliquip ut");
    CkJsonObjectW_UpdateString(json,L"items[1].externalId",L"reprehenderit ut");
    CkJsonObjectW_UpdateString(json,L"items[1].update.sourceType.set",L"timeSeries");
    CkJsonObjectW_UpdateString(json,L"items[1].update.sourceExternalId.set",L"adipisicing ullamco consequat");
    CkJsonObjectW_UpdateString(json,L"items[1].update.targetType.set",L"sequence");
    CkJsonObjectW_UpdateString(json,L"items[1].update.targetExternalId.set",L"aliqua");
    CkJsonObjectW_UpdateBool(json,L"items[1].update.confidence.setNull",TRUE);
    CkJsonObjectW_UpdateBool(json,L"items[1].update.startTime.setNull",FALSE);
    CkJsonObjectW_UpdateInt(json,L"items[1].update.endTime.set",51106464);
    CkJsonObjectW_UpdateBool(json,L"items[1].update.dataSetId.setNull",FALSE);
    CkJsonObjectW_UpdateString(json,L"items[1].update.labels.set[0].externalId",L"Lorem ipsum");
    CkJsonObjectW_UpdateString(json,L"items[1].update.labels.set[1].externalId",L"officia consectetur pariatur");

    CkHttpW_SetRequestHeader(http,L"content-type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"api-key",L"{{api-key}}");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/api/v1/projects/{{project}}/relationships/update",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "items": [
        {
            "externalId": "dolor amet sit",
            "update": {
                "sourceType": {
                    "set": "timeSeries"
                },
                "sourceExternalId": {
                    "set": "qui labor"
                },
                "targetType": {
                    "set": "file"
                },
                "targetExternalId": {
                    "set": "laborum"
                },
                "confidence": {
                    "setNull": true
                },
                "startTime": {
                    "set": 97867670
                },
                "endTime": {
                    "setNull": true
                },
                "dataSetId": {
                    "set": 8379377116294748
                },
                "labels": {
                    "set": [
                        {
                            "externalId": "ullamco anim"
                        },
                        {
                            "externalId": "aliquip ut"
                        }
                    ]
                }
            }
        },
        {
            "externalId": "reprehenderit ut",
            "update": {
                "sourceType": {
                    "set": "timeSeries"
                },
                "sourceExternalId": {
                    "set": "adipisicing ullamco consequat"
                },
                "targetType": {
                    "set": "sequence"
                },
                "targetExternalId": {
                    "set": "aliqua"
                },
                "confidence": {
                    "setNull": true
                },
                "startTime": {
                    "setNull": false
                },
                "endTime": {
                    "set": 51106464
                },
                "dataSetId": {
                    "setNull": false
                },
                "labels": {
                    "set": [
                        {
                            "externalId": "Lorem ipsum"
                        },
                        {
                            "externalId": "officia consectetur pariatur"
                        }
                    ]
                }
            }
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/relationships/update

Postman Collection Item JSON

{
  "id": "updateRelationships",
  "name": "Update relationships",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "relationships",
        "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 relationships between resources according to the partial definitions of the relationships given in the payload of the request. This means that fields not mentioned in the payload will remain unchanged. Up to 1000 relationships can be updated in one operation.\nTo delete a value from an optional value the `setNull` field should be set to `true`.\nThe order of the updated relationships in the response equals the order in the request.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"externalId\": \"dolor amet sit\",\n            \"update\": {\n                \"sourceType\": {\n                    \"set\": \"timeSeries\"\n                },\n                \"sourceExternalId\": {\n                    \"set\": \"qui labor\"\n                },\n                \"targetType\": {\n                    \"set\": \"file\"\n                },\n                \"targetExternalId\": {\n                    \"set\": \"laborum\"\n                },\n                \"confidence\": {\n                    \"setNull\": true\n                },\n                \"startTime\": {\n                    \"set\": 97867670\n                },\n                \"endTime\": {\n                    \"setNull\": true\n                },\n                \"dataSetId\": {\n                    \"set\": 8379377116294748\n                },\n                \"labels\": {\n                    \"set\": [\n                        {\n                            \"externalId\": \"ullamco anim\"\n                        },\n                        {\n                            \"externalId\": \"aliquip ut\"\n                        }\n                    ]\n                }\n            }\n        },\n        {\n            \"externalId\": \"reprehenderit ut\",\n            \"update\": {\n                \"sourceType\": {\n                    \"set\": \"timeSeries\"\n                },\n                \"sourceExternalId\": {\n                    \"set\": \"adipisicing ullamco consequat\"\n                },\n                \"targetType\": {\n                    \"set\": \"sequence\"\n                },\n                \"targetExternalId\": {\n                    \"set\": \"aliqua\"\n                },\n                \"confidence\": {\n                    \"setNull\": true\n                },\n                \"startTime\": {\n                    \"setNull\": false\n                },\n                \"endTime\": {\n                    \"set\": 51106464\n                },\n                \"dataSetId\": {\n                    \"setNull\": false\n                },\n                \"labels\": {\n                    \"set\": [\n                        {\n                            \"externalId\": \"Lorem ipsum\"\n                        },\n                        {\n                            \"externalId\": \"officia consectetur pariatur\"\n                        }\n                    ]\n                }\n            }\n        }\n    ]\n}"
    }
  }
}