简体   繁体   English

如何使用 nodejs 在 mailchimp 订阅者列表中创建标签?

[英]how to create tags in the lists of mailchimp subscriber using nodejs?

I had created the mail subscription using mailchimp.我使用 mailchimp 创建了邮件订阅。 The mail id is listed in the lists of mailchimp, but i want to pass the firstname,lastname and want to create a tag while doing the mailchimp subscription.邮件 ID 列在 mailchimp 列表中,但我想传递名字、姓氏并希望在订阅 mailchimp 时创建一个标签。 but now i am listing only the mail under my list.. when i am trying to create the tag via postman, the tags are created, but i want to add through api code.但现在我只列出我列表下的邮件.. 当我尝试通过 postman 创建标签时,标签已创建,但我想通过 api 代码添加。

var mailchimpInstance   = '***',
    listUniqueId        = '*********',
    mailchimpApiKey     = '*****************';

app.post('/signup', function (req, res) {
    request
        .post('https://' + mailchimpInstance + '.api.mailchimp.com/3.0/lists/' + listUniqueId + '/members/')
        .set('Content-Type', 'application/json;charset=utf-8')
        .set('Authorization', 'Basic ' + new Buffer('any:' + mailchimpApiKey ).toString('base64'))
        .send({
          'email_address': req.body.email,
          'status': 'subscribed',
          'merge_fields': {
            "FNAME": req.body.fname,
            "LNAME": req.body.lname
            }
        })
        .end(function(err, response) {
         if (response.status < 300 || (response.status === 400 && response.body.title === "Member Exists")) {
          res.send('Sign Up Success :)');
          } else {
                res.send('Sign Up Failed :(');
              }
              console.log(req.body.email);
          });

    });

This code is for sending the email to the lists..in this code the firstname and lastname is not listed in the lists of mailchimp..and i also need to create tags using this api此代码用于将 email 发送到列表中。在此代码中,名字和姓氏未列在 mailchimp 列表中。我还需要使用此 api 创建标签

There's a 'tags' body parameter which accepts an array and adds the tags to the mail id. 有一个“标签”主体参数,它接受一个数组并将标签添加到邮件ID。 Here's the documentation: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#%20 以下是文档: https : //developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#%20

If you want to create an email address AND add tags, you need to specify the tag as an array in the members field.如果要创建 email 地址并添加标签,则需要在成员字段中将标签指定为数组。

This drove me nuts as I noticed it had for a lot of other people reading through Stackoverflow.这让我发疯了,因为我注意到很多其他人通过 Stackoverflow 阅读它。

In your code, you would add the below when you are calling send.在您的代码中,您将在调用发送时添加以下内容。

In the below example, I had already created a tag:在下面的示例中,我已经创建了一个标签:

  var data = {
    status: "active",
    members:[
      {
      tags: ["yourtagname"],
      email_address: email,
      status: "subscribed",
      merge_fields: {
        FNAME: firstName,
        LNAME: lastName,
      },
      }
    ],
    
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将订阅者添加到我的 mailchimp 订阅者列表 - Add subscriber to my mailchimp subscriber list 如何使用nodeJS将订阅者角色和发布者角色添加到谷歌云发布订阅的死信? - How to add subscriber role and publisher role to deadletter for google cloud pubsub using nodeJS? 如何使用 NodeJS 创建图表? - How to create charts using NodeJS? Node + Mailchimp NPM:如何将订户添加到列表中并包含他们的名字和姓氏? - Node + Mailchimp NPM: How to add a subscriber to a list and include their first and last name? 如何在Node.js中通过mailchimp-api-v3提交表单(添加订户)? - How to submit a form (add a subscriber) by mailchimp-api-v3 in Node.js? 使用节点 https 将订阅者添加到 mailchimp 3.0 - Adding subscriber to mailchimp 3.0 with node https 在 nodeJs 中使用 mailchimp api 时出现套接字挂断错误 - Getting socket hangup error when using mailchimp api in nodeJs 如果不使用nodejs,如何在xml文件中动态插入结束标记? - How to dynamically insert closing tags in xml file if not present using nodejs? 如何使用NodeJS读取字符串中xml标签之间的文本 - How to read text between xml tags in a string using NodeJS 使用Nodejs进行网络抓取- <ul> 标签 - Webscraping using Nodejs - <ul> tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM