Chilkat Online Tools

Objective-C / Cognite API v1 / Create events

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": [
//     {
//       "externalId": "incididunt cillum adipisicing",
//       "dataSetId": 423131483236284,
//       "startTime": 44041889,
//       "endTime": 96620943,
//       "type": "repr",
//       "subtype": "in qui nisi amet adipisicing",
//       "description": "occaecat labore aute aliquip culpa",
//       "metadata": {},
//       "assetIds": [
//         4718222394395170,
//         910139302320326
//       ],
//       "source": "tempor amet"
//     },
//     {
//       "externalId": "eiusmod non occaecat Lorem veniam",
//       "dataSetId": 1722008537542636,
//       "startTime": 25642627,
//       "endTime": 13905808,
//       "type": "reprehenderit ut voluptate ea in",
//       "subtype": "ut mollit irure cupidatat nulla",
//       "description": "quis culpa dolore",
//       "metadata": {},
//       "assetIds": [
//         3955311648854054,
//         7221931367126430
//       ],
//       "source": "consectetur"
//     }
//   ]
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"items[0].externalId" value: @"incididunt cillum adipisicing"];
[json UpdateInt: @"items[0].dataSetId" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"items[0].startTime" value: [NSNumber numberWithInt: 44041889]];
[json UpdateInt: @"items[0].endTime" value: [NSNumber numberWithInt: 96620943]];
[json UpdateString: @"items[0].type" value: @"repr"];
[json UpdateString: @"items[0].subtype" value: @"in qui nisi amet adipisicing"];
[json UpdateString: @"items[0].description" value: @"occaecat labore aute aliquip culpa"];
[json UpdateNewObject: @"items[0].metadata"];
[json UpdateInt: @"items[0].assetIds[0]" value: [NSNumber numberWithInt: 4718222394395170]];
[json UpdateInt: @"items[0].assetIds[1]" value: [NSNumber numberWithInt: 910139302320326]];
[json UpdateString: @"items[0].source" value: @"tempor amet"];
[json UpdateString: @"items[1].externalId" value: @"eiusmod non occaecat Lorem veniam"];
[json UpdateInt: @"items[1].dataSetId" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"items[1].startTime" value: [NSNumber numberWithInt: 25642627]];
[json UpdateInt: @"items[1].endTime" value: [NSNumber numberWithInt: 13905808]];
[json UpdateString: @"items[1].type" value: @"reprehenderit ut voluptate ea in"];
[json UpdateString: @"items[1].subtype" value: @"ut mollit irure cupidatat nulla"];
[json UpdateString: @"items[1].description" value: @"quis culpa dolore"];
[json UpdateNewObject: @"items[1].metadata"];
[json UpdateInt: @"items[1].assetIds[0]" value: [NSNumber numberWithInt: 3955311648854054]];
[json UpdateInt: @"items[1].assetIds[1]" value: [NSNumber numberWithInt: 7221931367126430]];
[json UpdateString: @"items[1].source" value: @"consectetur"];

[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}}/events" 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": [
        {
            "externalId": "incididunt cillum adipisicing",
            "dataSetId": 423131483236284,
            "startTime": 44041889,
            "endTime": 96620943,
            "type": "repr",
            "subtype": "in qui nisi amet adipisicing",
            "description": "occaecat labore aute aliquip culpa",
            "metadata": {},
            "assetIds": [
                4718222394395170,
                910139302320326
            ],
            "source": "tempor amet"
        },
        {
            "externalId": "eiusmod non occaecat Lorem veniam",
            "dataSetId": 1722008537542636,
            "startTime": 25642627,
            "endTime": 13905808,
            "type": "reprehenderit ut voluptate ea in",
            "subtype": "ut mollit irure cupidatat nulla",
            "description": "quis culpa dolore",
            "metadata": {},
            "assetIds": [
                3955311648854054,
                7221931367126430
            ],
            "source": "consectetur"
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/events

Postman Collection Item JSON

{
  "id": "createEvents",
  "name": "Create events",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "events"
      ],
      "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": "Creates multiple event objects in the same project. It is possible to post a maximum of 1000 events per request.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"externalId\": \"incididunt cillum adipisicing\",\n            \"dataSetId\": 423131483236284,\n            \"startTime\": 44041889,\n            \"endTime\": 96620943,\n            \"type\": \"repr\",\n            \"subtype\": \"in qui nisi amet adipisicing\",\n            \"description\": \"occaecat labore aute aliquip culpa\",\n            \"metadata\": {},\n            \"assetIds\": [\n                4718222394395170,\n                910139302320326\n            ],\n            \"source\": \"tempor amet\"\n        },\n        {\n            \"externalId\": \"eiusmod non occaecat Lorem veniam\",\n            \"dataSetId\": 1722008537542636,\n            \"startTime\": 25642627,\n            \"endTime\": 13905808,\n            \"type\": \"reprehenderit ut voluptate ea in\",\n            \"subtype\": \"ut mollit irure cupidatat nulla\",\n            \"description\": \"quis culpa dolore\",\n            \"metadata\": {},\n            \"assetIds\": [\n                3955311648854054,\n                7221931367126430\n            ],\n            \"source\": \"consectetur\"\n        }\n    ]\n}"
    }
  }
}