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

如何使用Brevo API发送WhatsApp消息?遇权限拒绝报错求助

解决WhatsApp消息发送接口的"permission_denied"错误

我参考官方文档编写了发送WhatsApp消息的代码,但测试时返回错误:

{"code": "permission_denied", "message": "Your account is not registered"}

编写的代码如下:

import axios from 'axios';

const API_KEY = '/i got api key from brevo SMTP & API page/';

export default async function handler(req, res) {
  if (req.method === 'POST') {
    const { phoneNumbers, Message } = req.body;

    for (const phone of phoneNumbers) {
        const options = {
            method: 'POST',
            headers: {
              accept: 'application/json',
              'content-type': 'application/json',
              'api-key': API_KEY,
            },
            body: JSON.stringify({
                senderNumber: '123456789', 
                text: Message, 
                contactNumbers: [phone,]
            })
        };

            try {
                const response = await axios.request(options);
                console.log(`Message sent successfully to ${phone}`);
                console.log('Response data:', response.data);
            } catch (error) {
                console.error(`Error sending message to ${phone}:`, error.message);
            }
        }
    
            res.status(200).json({ message: 'Messages sent' });
        } else {
            res.status(405).json({ error: 'Method not allowed' });
        }
    }

排查与解决步骤:

  • 完成WhatsApp账号注册流程:错误提示明确说明账号未注册,需登录Brevo后台完成WhatsApp业务账号的申请、资质审核及号码绑定,这是使用该接口的前提,仅获取SMTP API Key无法使用WhatsApp服务。
  • 确认API Key权限:检查你的API Key是否关联了已开通WhatsApp服务的账号,部分场景下SMTP权限和WhatsApp权限是分开开通的,需确保账号已激活WhatsApp消息功能。
  • 验证发送号码有效性:代码中senderNumber必须是在Brevo平台完成验证并绑定的官方WhatsApp发送号码,不能使用未认证的测试号码。
  • 核对参数格式:检查contactNumbers中的号码格式是否正确(需包含国际区号,如+123456789),格式错误也可能触发权限类错误提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 01:03:27