我的 nodeJS 云函数在 client.request 崩溃
My nodeJS cloud function crashes on client.request
尝试使用 HTTP 触发器创建云函数 NodeJS,但它总是崩溃并向我抛出错误 500。查看日志它只是告诉我
client.request is not a function
我的代码如下所示,我只是将 POST 请求正文电子邮件发送到 SendGrid。我从 SendGrid 获取代码并在本地测试它而不是在 (req, res) 请求中并且工作正常。
require('dotenv').config()
const client = require('@sendgrid/mail')
const sendgridKey = process.env.sendgrid_api_key
client.setApiKey(sendgridKey);
exports.welcomeEmail = (req, res) => {
const data = {
"contacts": [
{
"email": req.body.record.email
}
],
"list_ids": ["somevalue"]
};
const request = {
url: `/v3/marketing/contacts`,
method: 'PUT',
body: data
}
client.request(request)
.then(([response, body]) => {
let message = response.body
return message
})
.catch(error => {
let message = error
return message
});
res.status(200).send(message);
};
您打算改用 this package 吗?
const client = require('@sendgrid/client');
的示例相比,此包的示例看起来更像您想要执行的操作
尝试使用 HTTP 触发器创建云函数 NodeJS,但它总是崩溃并向我抛出错误 500。查看日志它只是告诉我
client.request is not a function
我的代码如下所示,我只是将 POST 请求正文电子邮件发送到 SendGrid。我从 SendGrid 获取代码并在本地测试它而不是在 (req, res) 请求中并且工作正常。
require('dotenv').config()
const client = require('@sendgrid/mail')
const sendgridKey = process.env.sendgrid_api_key
client.setApiKey(sendgridKey);
exports.welcomeEmail = (req, res) => {
const data = {
"contacts": [
{
"email": req.body.record.email
}
],
"list_ids": ["somevalue"]
};
const request = {
url: `/v3/marketing/contacts`,
method: 'PUT',
body: data
}
client.request(request)
.then(([response, body]) => {
let message = response.body
return message
})
.catch(error => {
let message = error
return message
});
res.status(200).send(message);
};
您打算改用 this package 吗?
const client = require('@sendgrid/client');
的示例相比,此包的示例看起来更像您想要执行的操作