You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用NerdGraph API创建NewRelic告警工作流遇通道不存在错误

解决NewRelic工作流创建时“找不到指定Channel ID”的问题

问题背景

通过编程方式创建NewRelic工作流,按顺序完成destination、channel的创建并获取到channel ID后,调用aiWorkflowsCreateWorkflow接口创建工作流时,返回如下错误:

{
  "data": {
    "aiWorkflowsCreateWorkflow": {
      "errors": [
        {
          "description": "A channel with id XXXXXXXXXXXX was not found",
          "type": "INVALID_PARAMETER"
        }
      ],
      "workflow": null
    }
  }
}

尝试使用非AI版本的创建channel接口后问题仍未解决。相关NerdGraph mutation代码如下:

创建Destination的代码

mutation CreateDestination {
  aiNotificationsCreateDestination(
    accountId: {{ accountId }}
    destination: {
      auth: {type: BASIC}, 
      name: "{{ name }}", 
      properties: {key: "url", value: "{{ url }}"}, 
      type: WEBHOOK
    }
  ) {
    destination {
      id
      name
      properties {
        displayValue
        label
      }
      guid
      active
    }
    error {
      ... on AiNotificationsConstraintsError {
        constraints {
          dependencies
        }
      }
      ... on AiNotificationsDataValidationError {
        details
      }
      ... on AiNotificationsResponseError {
        description
      }
    }
  }
}

创建Channel的代码

mutation {
  aiNotificationsCreateChannel(
    accountId: {{ account_id }}
    channel: {
      destinationId: "{{ destination_id }}", 
      name: "{{ channel_name }}", 
      product: ALERTS, 
      properties: {
        displayValue: null, 
        key: "payload", 
        label: null, 
        value: """{{ properties_value }}""",
      }, 
      type: WEBHOOK
    }
  ) {
    channel {
      accountId
      active
      createdAt
      destinationId
      id
      name
      product
      properties {
        displayValue
        key
        label
        value
      }
    }
    error {
      ... on AiNotificationsConstraintsError {
        constraints {
          dependencies
          name
        }
      }
      ... on AiNotificationsResponseError {
        description
        details
        type
      }
      ... on AiNotificationsDataValidationError {
        details
        fields {
          field
          message
        }
      }
    }
  }
}

创建Workflow的代码

mutation {
    aiWorkflowsCreateWorkflow(
        accountId: {{ account_id }}
        createWorkflowData: {
            destinationConfigurations: [
                {% for channel in destination_configurations %}
                {
                    channelId: "{{ channel.channelId }}",
                    notificationTriggers: [{{ channel.notificationTriggers | join(', ') }}],
                    updateOriginalMessage: {{ channel.updateOriginalMessage | lower }}
                }{% if not loop.last %},{% endif %}
                {% endfor %}
            ],
            name: "{{ workflow_name }}",
            workflowEnabled: true,
            mutingRulesHandling: DONT_NOTIFY_FULLY_MUTED_ISSUES,
            issuesFilter: {
                name: "{{ issues_filter_name }}",
                predicates: {
                    attribute:  "labels.policyIds",
                    operator: EXACTLY_MATCHES
                    values: [ " {{ issues_filter_values }}" ]
                },
                type: FILTER
            },
            destinationsEnabled: true
        }
    ) {
    workflow {
      id
      name
      destinationConfigurations {
        channelId
        notificationTriggers
        updateOriginalMessage
        name
      }
      workflowEnabled
      mutingRulesHandling
      issuesFilter {
        name
        predicates {
          attribute
          operator
          values
        }
        type
      }
      destinationsEnabled
      guid
    }
    errors {
      description
      type
    }
  }
}

排查与解决步骤

1. 确认Account ID完全一致

检查创建destination、channel、workflow时使用的accountId是否完全匹配,包括变量名(如代码中{{ accountId }}和{{ account_id }}是否指向同一值)、无多余空格或格式错误。NewRelic资源与账号强绑定,跨账号引用会直接导致找不到channel。

2. 验证Channel的有效性与状态

调用查询接口确认channel是否存在且处于激活状态:

query GetChannelStatus {
  aiNotificationsChannel(accountId: {{ account_id }}, channelId: "{{ channel_id }}") {
    id
    active
    accountId
    product
  }
}
  • 若返回结果为空,说明channel未成功创建,需检查创建channel的接口返回错误信息;
  • 若active为false,需调用aiNotificationsUpdateChannel接口激活channel,或检查关联的destination是否正常;
  • 确认product字段为ALERTS,工作流仅支持引用属于Alerts产品的channel。

3. 修正模板渲染的格式问题

检查workflow代码中以下细节:

  • channelId: "{{ channel.channelId }}"是否渲染后带有多余空格,需确保ID无前后空格;
  • 修正issuesFilter中的values: [ " {{ issues_filter_values }}" ],去掉引号内的空格,改为values: ["{{ issues_filter_values }}"],避免格式错误影响参数解析。

4. 等待资源同步延迟

NewRelic部分资源创建后存在短暂的同步延迟,可在创建channel后等待1-2秒再调用工作流创建接口。

5. 保持接口版本一致性

若使用AI版本的aiNotificationsCreateChannel创建channel,需配套使用aiWorkflowsCreateWorkflow创建工作流,避免混合不同版本接口导致的兼容性问题。

内容的提问来源于stack exchange,提问作者Shivangi Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 06:45:15