You often need to retrieve
already persisted event data from Supply Chain Intelligence
Suite, for use in your application. For
example, you might have registered a KPI Rule and then later want to query for the KPI metric events
so that you can show them on your dashboard. In this tutorial, you learn how issue a variety of
basic queries to fetch business rule events from Supply Chain Intelligence
Suite's GraphQL APIs.
Before you begin
- If you are new to GraphQL, complete the graphql.com tutorials until you
feel comfortable with GraphQL API basics.
- Add JSON Web Token authentication to HTTP request headers. For more information, see
Creating authentication tokens.
Note: If you do not pass this auth header, Supply Chain Intelligence
Suite APIs
return a 401 error.
About this task
You learn about the following tasks:
- How to write a basic GraphQL query.
- How to use Supply Chain Intelligence
Suite's query services to retrieve an already persisted business event.
-
How to parse the returned event for use in your application.
Procedure
- Navigate to the GraphiQL visual editor.
- Input the following sample query into the left side of the editor. If you have a sample
rule ID from another tutorial, replace the ID below with your other rule's ID:
query{
businessRuleEvents(
simpleFilter: {
rule: {
id: "4cb28d31-4ebc-476c-8460-c79ecd8bbc12"
}
},
cursorParams: {
first: 1 #Maximum number of items to return
}
){
totalCount
pageInfo {
endCursor
hasNextPage
}
edges {
cursor
object {
eventCode
timestampEventOccurred
timestampEventReceived
}
}
}
}
- Click the run button on the left-top side of the editor. This runs the query and retrieve
the business events that are already stored for this rule.
The response shows the following result on the right side of the editor:
{
"data": {
"businessRuleEvents": {
"totalCount": 39,
"pageInfo": {
"endCursor": "NGNiMjhkMzEtNGViYy00NzZjLTg0NjAtYzc5ZWNkOGJiYzEyX2V2ZW50ZGV0YWlscy5ldmVudHNvdXJjZS50cmFuc2FjdGlvbnR5cGVfODIwLHRlbmFudGlkXzNlMzc0NDJkLTIyNjUtNDg3ZC1hNTJmLTVlYWQxMTg5M2IxYSxtaW51dGVfMjAwOS0wOC0zMHQxODo0MF8=",
"hasNextPage": true
},
"edges": [
{
"cursor": "NGNiMjhkMzEtNGViYy00NzZjLTg0NjAtYzc5ZWNkOGJiYzEyX2V2ZW50ZGV0YWlscy5ldmVudHNvdXJjZS50cmFuc2FjdGlvbnR5cGVfODIwLHRlbmFudGlkXzNlMzc0NDJkLTIyNjUtNDg3ZC1hNTJmLTVlYWQxMTg5M2IxYSxtaW51dGVfMjAwOS0wOC0zMHQxODo0MF8=",
"object": {
"eventCode": "businessEvent",
"timestampEventOccurred": "2009-08-30T18:40:16+0000",
"timestampEventReceived": "2019-12-05T12:07:00"
}
}
]
}
}
}
Note: This is a live system. The exact response that you see might vary from the above screen
capture as new events are constantly being fired.
What to do next
- You can modify the criteria and the attributes to return and rerun the query as many times as
you like.
- Extract the metric from the returned JSON and use as needed.