NerdGraph tutorial: Create and manage applied intelligence workflows
For New Relic applied intelligence, you can create and manage workflows using our NerdGraph API.
List and filter workflows
The workflows query allows you to paginate through all of your workflows per account. It also allows some filtering functionality on the account workflows. Here are some example use cases:
{
actor {
account(id: YOUR_ACCOUNT_ID) {
aiWorkflows {
workflows(filters: {}) {
entities {
id
name
workflowEnabled
destinationConfigurations {
channelId
name
type
}
enrichments {
configuration {
... on AiWorkflowsNrqlConfigurationDto {
query
}
}
id
name
}
filter {
predicates {
attribute
operator
values
}
}
}
nextCursor
totalCount
}
}
}
}
}
In order to paginate through your workflows, you must request the nextCursor field on your initial query.
With cursor pagination, you continue to make a request through the result set until the nextCursor that's returned from the response comes back empty. This indicates you've reached the end of your results.
First call:
{
actor {
account(id: YOUR_ACCOUNT_ID) {
aiWorkflows {
workflows(filters: {}) {
entities {
id
name
}
nextCursor
totalCount
}
}
}
}
}
A channel ID is unique and so can't be used in multiple workflows or used multiple times in the same workflow.
The issuesFilter attribute decides which issue events will be caught by the workflow.
By keeping the predicates attribute's value as an empty list, the workflow will catch all the possible issue events. When you select an attribute value you can then filter issue events.
For example, we can choose an attribute that only filters issues that are relevant to a specific team:
mutation {
aiWorkflowsCreateWorkflow(accountId: YOUR_ACCOUNT_ID, createWorkflowData: {destinationsEnabled: true, workflowEnabled: true, name: "API Demo Workflow", issuesFilter: {name: "team specific issues", predicates: [{ attribute: "accumulations.tag.team", operator: EXACTLY_MATCHES, values:["security"]}], type: FILTER}, destinationConfigurations: {channelId: "CHANNEL_ID"}, enrichmentsEnabled: true, enrichments: {nrql: []}, , mutingRulesHandling: DONT_NOTIFY_FULLY_MUTED_ISSUES}) {
workflow {
id
name
destinationConfigurations {
channelId
name
type
}
enrichmentsEnabled
destinationsEnabled
issuesFilter {
accountId
id
name
predicates {
attribute
operator
values
}
type
}
lastRun
workflowEnabled
mutingRulesHandling
}
errors {
description
type
}
}
}
Update a workflow
When you update a workflow, note the only mandatory attributes you need to supply are the workflow ID and account ID. The rest are optional. For example, you only need to supply the name if you only intend to update the name.
Here's an example of updating a workflow:
mutation {
aiWorkflowsUpdateWorkflow(accountId: YOUR_ACCOUNT_ID, updateWorkflowData: {name: "Updated API Demo Workflow", id: WORKFLOW_ID}) {
workflow {
id
name
destinationConfigurations {
channelId
name
type
}
enrichmentsEnabled
destinationsEnabled
issuesFilter {
accountId
id
name
predicates {
attribute
operator
values
}
type
}
lastRun
workflowEnabled
mutingRulesHandling
}
errors {
description
type
}
}
}
Delete a workflow
Here's an example of deleting a workflow:
mutation {
aiWorkflowsDeleteWorkflow(id: WORKFLOW_ID, accountId: YOUR_ACCOUNT_ID) {
id
errors {
description
type
}
}
}
Test a workflow
The test searches for previous issues that match your inputs and creates a fake notification based on that. If no previous issue matching your inputs has been found it will return an error.
For example:
mutation {
aiWorkflowsTestWorkflow(accountId: YOUR_ACCOUNT_ID, testWorkflowData: {destinationConfigurations: {channelId: CHANNEL_ID, type: SLACK}, issuesFilter: {predicates: [], type: FILTER}}) {
status
notificationResponses {
status
evidence
channelId
}
errors {
description
type
}
}
}