gpt4 book ai didi

javascript - 如何使用云功能向 Mailchimp 事件添加新用户?

转载 作者:太空宇宙 更新时间:2023-11-04 03:13:18 26 4
gpt4 key购买 nike

我正在尝试将新用户添加到 Mailchimp 事件中。我收到两个错误,第一个错误是:

函数返回未定义的、预期的 Promise 或值

第二个错误的日志是:

Error: The resource submitted could not be validated. For field-specific details, see the 'errors' array.
type: 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
title: 'Invalid Resource',
status: 400,
detail: 'The resource submitted could not be validated. For field-specific details, see the \'errors\' array.',
instance: '549e8553-5ef1-4600-9271-07255f4673fe',
errors:
[ { field: 'status',
message: 'The value you selected is not a valid choice.' } ] }

这是我的功能

   exports.userCreated = functions.auth.user().onCreate((user) => {
const email = user.email;
// const displayName = user.name;

// make Mailchimp API request to add a user
Mailchimp
.post('/lists/id/members', {
email_address: email,
status: 'Signed Up',
// optional: requires additional setup
merge_fields: {
"EMAIL" : email
}
})
.then(function(results) {
console.log('Successfully added new Firebase user', email, 'to Mailchimp list',results);
})
.catch(function(err) {
console.log(email);
console.log('Mailchimp: Error while attempting to add registered subscriber —', err);
});
});

最佳答案

您检测到您的云函数中有两个错误:

第一个是你必须在后台触发的云函数中返回一个Promise(或一个值),以向平台表明它已经完成。请观看 Firebase video series 中有关“JavaScript Promises”的三个视频了解有关此关键点的更多详细信息。

第二个问题是您的字段 status 值“不是有效的选择”。看看 Mailchimp doc ,如果我没记错的话,正确的值为:

已订阅待定取消订阅已清除

<小时/>

因此,以下更改应该可以解决问题:

   exports.userCreated = functions.auth.user().onCreate((user) => {
const email = user.email;
// const displayName = user.name;

// make Mailchimp API request to add user
return mailchimp
.post('/lists/id/members', {
email_address: email,
status: 'subscribed', // For example, it's up to you to find the correct status
// optional: requires additional setup
merge_fields: {
"EMAIL" : email
}
})
.then(function(results) {
console.log('Successfully added new Firebase user', email, 'to Mailchimp list',results);
return null;
})
.catch(function(err) {
console.log(email);
console.log('Mailchimp: Error while attempting to add registered subscriber —', err);
return null;
});
});

关于javascript - 如何使用云功能向 Mailchimp 事件添加新用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60083558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com