Monitoring cases
In this example you will see an example of how to retrieve information from all your cases. The same principles can be applied to single cases.
GraphQL query for getCases
Below here is the GraphQL query for getCases
. The operations could look like this but could be altered depending on
your needs. For example if the risk assessment notes is also needed, you just need to add riskAssessmentNotes
.
query getCases($amount: Int) {
cases(amount: $amount) {
items {
item {
id
name
status
statusText {
en
}
riskAssessmentNotes
riskAssessmentConclusion
}
}
}
}
Calling this query gets you the following response:
{
"data": {
"cases": {
"items": [
{
"item": {
"id": "HUO6KI4roqA",
"name": "Novo Nordisk Denmark A/S",
"status": "PENDING",
"statusText": {
"en": "Awaiting contact"
},
"riskAssessmentNotes": "Lorem ipsum",
"riskAssessmentConclusion": "LOW"
}
},
{
"item": {
"id": "08PCw-iy0Q8",
"name": "PENNEO A/S",
"status": "PENDING",
"statusText": {
"en": "Awaiting contact"
},
"riskAssessmentNotes": "",
"riskAssessmentConclusion": "LOW"
}
}
]
}
}
}
Getting cases
The following will be an example of how to get statuses from existing cases. You might need to dig further into the data to show more specific data. Please refer to the case documentation for more context.
public async getCases(numOfCases: any): Promise<FetchResult> {
return this.gqlClient.query({
query: GetCases,
variables: {
amount: numOfCases,
},
});
}
Monitoring a single case
If you are looking to get the status of a single case, you can use getCases
as well.
You will need to add filters in order to choose the case you are looking for.
The query looks mostly the same but now has strawberryShakeFilters
, which allows you to filter the cases.
query getCases($amount: Int, $strawberryShakeFilters: [StrawberryShakeCaseFilters]) {
cases(amount: $amount, strawberryShakeFilters: $strawberryShakeFilters) {
items {
item {
id
name
status
statusText {
en
}
riskAssessmentNotes
riskAssessmentConclusion
}
}
}
}
For example you can call the following
public async getCasesByName(numOfCases: number, name: string): Promise<FetchResult<GetCasesWithStrawberryFiltersQuery>> {
return this.gqlClient.query({
query: GetCasesWithStrawberryFilters,
variables: {
amount: numOfCases,
strawberryShakeFilters: [
{
name: { sameAs: name },
},
],
},
});
}
}
As such
const publicApiClient = new PublicApiClient();
const result = await publicApiClient.getCasesByName(100, 'PENNEO A/S');
console.log(result.data?.cases?.items);
To get the following output. Beware that if you have more clients with the same name and set the amount to 1, you will only get the first of them.
[
{
__typename: 'CollectionItem_Case',
item: {
__typename: 'Case',
id: '08PCw-iy0Q8',
name: 'PENNEO A/S',
status: 'PENDING',
"statusText": {
"en": "Awaiting contact"
},
riskAssessmentNotes: '',
riskAssessmentConclusion: 'LOW'
}
}
]