Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

CONNECT data services developer documentation

Event Type Store and GraphQL API usage examples

  • Last UpdatedDec 19, 2023
  • 1 minute read

The following sample types demonstrate how Event Types and Reference Data Types can be used together to facilitate the creation and querying of events in the GraphQL API.

First, we create a Reference Data Type referencing an external asset:

POST /api/v1-preview/Tenants/{tenantId}/Namespaces/{namespaceId}/ReferenceDataTypes/assetReference
 

{
    "Id": "assetReference",
    "Name": "assetReference",
    "Properties":
    [
        {
            "Id": "SourceId",
            "PropertyTypeCode": "String"
        },
        {
            "Id": "ResourceId",
            "PropertyTypeCode": "String"
        }
    ]
}

Then, we create an Event Type with a property referencing the previously created Reference Data Type:

POST /api/v1-preview/Tenants/{tenantId}/Namespaces/{namespaceId}/EventTypes/LowProductionEvent
 

{
    "Id": "LowProductionEvent",
    "Name": "LowProductionEvent",
    "Properties":
    [
        {
            "Id": "referenceAssets",
            "PropertyTypeCode": "ReferenceData",
            "Flags": "IsCollection",
            "PropertyTypeId": "assetReference"
        },
        {
            "Id": "totalRevenueLoss",
            "PropertyTypeCode": "Double"
        }
    ]
}

Finally, once events of the above Event Type have been created, we use the GraphQL API to query these assets, allowing the user to gather data about related events.
 

{
    events {
        LowProductionEvent {
            startTime
            endTime
            duration
            referenceAssets {
                id
                name
            }
            totalRevenueLoss
        }
    }
}

A sample result of the query is shown below.

 

{
    "data": {
        "events": {
            "LowProductionEvent": [
                {
                    "startTime": "2023-06-01T05:43:27.00Z",
                    "endTime": "2023-06-01T06:43:27.00Z",
                    "duration": "01:00:00",
                    "referenceAssets": [
                        {
                            "id": "Asset1",
                            "name": "Asset1"
                        },
                        {
                            "id": "Asset2",
                            "name": "Asset2"
                        }
                    ],
                    "totalRevenueLoss": 5.2
                },
                {
                    "startTime": "2023-06-03T09:00:02.00Z",
                    "endTime": "2023-06-03T10:00:02.00Z",
                    "duration": "01:00:00",
                    "referenceAssets": [
                        {
                            "id": "Asset3",
                            "name": "Asset3"
                        }
                    ],
                    "totalRevenueLoss": 12.1
                },
                {
                    "startTime": "2023-06-03T15:20:25.00Z",
                    "endTime": "2023-06-03T16:20:25.00Z",
                    "duration": "01:00:00",
                    "referenceAssets": [
                        {
                            "id": "Asset3",
                            "name": "Asset3"
                        }
                    ],
                    "totalRevenueLoss": 33.56
                }
            ]
        }
    }
}
Related Links
TitleResults for “How to create a CRG?”Also Available in