Chilkat Online Tools

PureBasic / Cognite API v1 / Create events

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

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

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"items[0].externalId","incididunt cillum adipisicing")
    CkJsonObject::ckUpdateInt(json,"items[0].dataSetId",123)
    CkJsonObject::ckUpdateInt(json,"items[0].startTime",44041889)
    CkJsonObject::ckUpdateInt(json,"items[0].endTime",96620943)
    CkJsonObject::ckUpdateString(json,"items[0].type","repr")
    CkJsonObject::ckUpdateString(json,"items[0].subtype","in qui nisi amet adipisicing")
    CkJsonObject::ckUpdateString(json,"items[0].description","occaecat labore aute aliquip culpa")
    CkJsonObject::ckUpdateNewObject(json,"items[0].metadata")
    CkJsonObject::ckUpdateInt(json,"items[0].assetIds[0]",4718222394395170)
    CkJsonObject::ckUpdateInt(json,"items[0].assetIds[1]",910139302320326)
    CkJsonObject::ckUpdateString(json,"items[0].source","tempor amet")
    CkJsonObject::ckUpdateString(json,"items[1].externalId","eiusmod non occaecat Lorem veniam")
    CkJsonObject::ckUpdateInt(json,"items[1].dataSetId",123)
    CkJsonObject::ckUpdateInt(json,"items[1].startTime",25642627)
    CkJsonObject::ckUpdateInt(json,"items[1].endTime",13905808)
    CkJsonObject::ckUpdateString(json,"items[1].type","reprehenderit ut voluptate ea in")
    CkJsonObject::ckUpdateString(json,"items[1].subtype","ut mollit irure cupidatat nulla")
    CkJsonObject::ckUpdateString(json,"items[1].description","quis culpa dolore")
    CkJsonObject::ckUpdateNewObject(json,"items[1].metadata")
    CkJsonObject::ckUpdateInt(json,"items[1].assetIds[0]",3955311648854054)
    CkJsonObject::ckUpdateInt(json,"items[1].assetIds[1]",7221931367126430)
    CkJsonObject::ckUpdateString(json,"items[1].source","consectetur")

    CkHttp::ckSetRequestHeader(http,"content-type","application/json")
    CkHttp::ckSetRequestHeader(http,"api-key","{{api-key}}")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/api/v1/projects/{{project}}/events","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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