Objective-C / Cognite API v1 / Update assets
Back to Collection Items
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;
// 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": "ad"
// },
// "name": {
// "set": "incididunt proident in"
// },
// "description": {
// "setNull": true
// },
// "dataSetId": {
// "set": -49836609
// },
// "metadata": {
// "set": {}
// },
// "source": {
// "set": "sed laboris ut"
// },
// "parentId": {
// "set": 1285179828449184
// },
// "parentExternalId": {
// "set": "cupidatat"
// },
// "labels": {
// "set": [
// {
// "externalId": "sit anim ipsum"
// },
// {
// "externalId": "fugiat cillum"
// }
// ]
// }
// },
// "externalId": "deserunt "
// },
// {
// "update": {
// "externalId": {
// "setNull": false
// },
// "name": {
// "set": "aute"
// },
// "description": {
// "setNull": true
// },
// "dataSetId": {
// "set": -68427017
// },
// "metadata": {
// "add": {},
// "remove": [
// ]
// },
// "source": {
// "set": "incididunt proident aute consequat"
// },
// "parentId": {
// "set": 4455735300348148
// },
// "parentExternalId": {
// "set": "quis est mollit esse"
// },
// "labels": {
// "add": [
// {
// "externalId": "officia pariatur mollit sunt"
// },
// {
// "externalId": "pariatur veniam"
// }
// ],
// "remove": [
// {
// "externalId": "dolor nulla dolor non"
// },
// {
// "externalId": "ex"
// }
// ]
// }
// },
// "id": 7396120406053176
// }
// ]
// }
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"items[0].update.externalId.set" value: @"ad"];
[json UpdateString: @"items[0].update.name.set" value: @"incididunt proident in"];
[json UpdateBool: @"items[0].update.description.setNull" value: YES];
[json UpdateInt: @"items[0].update.dataSetId.set" value: [NSNumber numberWithInt: -49836609]];
[json UpdateNewObject: @"items[0].update.metadata.set"];
[json UpdateString: @"items[0].update.source.set" value: @"sed laboris ut"];
[json UpdateInt: @"items[0].update.parentId.set" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"items[0].update.parentExternalId.set" value: @"cupidatat"];
[json UpdateString: @"items[0].update.labels.set[0].externalId" value: @"sit anim ipsum"];
[json UpdateString: @"items[0].update.labels.set[1].externalId" value: @"fugiat cillum"];
[json UpdateString: @"items[0].externalId" value: @"deserunt "];
[json UpdateBool: @"items[1].update.externalId.setNull" value: NO];
[json UpdateString: @"items[1].update.name.set" value: @"aute"];
[json UpdateBool: @"items[1].update.description.setNull" value: YES];
[json UpdateInt: @"items[1].update.dataSetId.set" value: [NSNumber numberWithInt: -68427017]];
[json UpdateNewObject: @"items[1].update.metadata.add"];
[json UpdateNewArray: @"items[1].update.metadata.remove"];
[json UpdateString: @"items[1].update.source.set" value: @"incididunt proident aute consequat"];
[json UpdateInt: @"items[1].update.parentId.set" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"items[1].update.parentExternalId.set" value: @"quis est mollit esse"];
[json UpdateString: @"items[1].update.labels.add[0].externalId" value: @"officia pariatur mollit sunt"];
[json UpdateString: @"items[1].update.labels.add[1].externalId" value: @"pariatur veniam"];
[json UpdateString: @"items[1].update.labels.remove[0].externalId" value: @"dolor nulla dolor non"];
[json UpdateString: @"items[1].update.labels.remove[1].externalId" value: @"ex"];
[json UpdateInt: @"items[1].id" value: [NSNumber numberWithInt: 123]];
[http SetRequestHeader: @"content-type" value: @"application/json"];
[http SetRequestHeader: @"api-key" value: @"{{api-key}}"];
CkoHttpResponse *resp = [http PostJson3: @"https://domain.com/api/v1/projects/{{project}}/assets/update" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);
Curl Command
curl -X POST
-H "api-key: {{api-key}}"
-H "content-type: application/json"
-d '{
"items": [
{
"update": {
"externalId": {
"set": "ad"
},
"name": {
"set": "incididunt proident in"
},
"description": {
"setNull": true
},
"dataSetId": {
"set": -49836609
},
"metadata": {
"set": {}
},
"source": {
"set": "sed laboris ut"
},
"parentId": {
"set": 1285179828449184
},
"parentExternalId": {
"set": "cupidatat"
},
"labels": {
"set": [
{
"externalId": "sit anim ipsum"
},
{
"externalId": "fugiat cillum"
}
]
}
},
"externalId": "deserunt "
},
{
"update": {
"externalId": {
"setNull": false
},
"name": {
"set": "aute"
},
"description": {
"setNull": true
},
"dataSetId": {
"set": -68427017
},
"metadata": {
"add": {},
"remove": []
},
"source": {
"set": "incididunt proident aute consequat"
},
"parentId": {
"set": 4455735300348148
},
"parentExternalId": {
"set": "quis est mollit esse"
},
"labels": {
"add": [
{
"externalId": "officia pariatur mollit sunt"
},
{
"externalId": "pariatur veniam"
}
],
"remove": [
{
"externalId": "dolor nulla dolor non"
},
{
"externalId": "ex"
}
]
}
},
"id": 7396120406053176
}
]
}'
https://domain.com/api/v1/projects/{{project}}/assets/update
Postman Collection Item JSON
{
"id": "updateAssets",
"name": "Update assets",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"assets",
"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 the attributes of assets.",
"body": {
"mode": "raw",
"raw": "{\n \"items\": [\n {\n \"update\": {\n \"externalId\": {\n \"set\": \"ad\"\n },\n \"name\": {\n \"set\": \"incididunt proident in\"\n },\n \"description\": {\n \"setNull\": true\n },\n \"dataSetId\": {\n \"set\": -49836609\n },\n \"metadata\": {\n \"set\": {}\n },\n \"source\": {\n \"set\": \"sed laboris ut\"\n },\n \"parentId\": {\n \"set\": 1285179828449184\n },\n \"parentExternalId\": {\n \"set\": \"cupidatat\"\n },\n \"labels\": {\n \"set\": [\n {\n \"externalId\": \"sit anim ipsum\"\n },\n {\n \"externalId\": \"fugiat cillum\"\n }\n ]\n }\n },\n \"externalId\": \"deserunt \"\n },\n {\n \"update\": {\n \"externalId\": {\n \"setNull\": false\n },\n \"name\": {\n \"set\": \"aute\"\n },\n \"description\": {\n \"setNull\": true\n },\n \"dataSetId\": {\n \"set\": -68427017\n },\n \"metadata\": {\n \"add\": {},\n \"remove\": []\n },\n \"source\": {\n \"set\": \"incididunt proident aute consequat\"\n },\n \"parentId\": {\n \"set\": 4455735300348148\n },\n \"parentExternalId\": {\n \"set\": \"quis est mollit esse\"\n },\n \"labels\": {\n \"add\": [\n {\n \"externalId\": \"officia pariatur mollit sunt\"\n },\n {\n \"externalId\": \"pariatur veniam\"\n }\n ],\n \"remove\": [\n {\n \"externalId\": \"dolor nulla dolor non\"\n },\n {\n \"externalId\": \"ex\"\n }\n ]\n }\n },\n \"id\": 7396120406053176\n }\n ]\n}"
}
}
}