【问题标题】:SendGrid NodeJS - Client.request() is not a functionSendGrid NodeJS - Client.request() 不是函数
【发布时间】:2018-09-20 14:21:30
【问题描述】:

我正在尝试创建一个用户,然后通过 sendgrid api 将他们添加到一个列表中,但我一直收到错误消息说 Client.request 不是一个函数,但显然它是一个函数。

function createNewUser(list: number) {
    return Client.request({
      method: 'POST',
      url: '/v3/contactdb/recipients',
      body: JSON.stringify([
        {
          email: format.email,
          first_name: format.name.split(' ')[0] || '',
          last_name: format.name.split(' ')[1] || ''
        }
      ])
    })
      .then(newUsers => {
        const ids = (<any>newUsers).persisted_recipients;
        return ids.forEach(async user => {
          console.log(list, user);
          Client.request({
            method: 'POST',
            url: `/v3/contactdb/lists/%7B${list}%7D/recipients/%7B${
              user.id
            }%7D`,
            body: 'null'
          })
            .then(success => {
              console.log(`${user.id} as been added to ${list}`);
              return res.status(200).send('OK');
            })
            .catch(err => {
              console.log(err);
              return res.status(500).send(err);
            });
        });
      })
      .catch(err => res.status(500).send(err));
  }

【问题讨论】:

    标签: node.js typescript sendgrid


    【解决方案1】:

    即使我遇到了同样的问题,在花了半个小时之后,我也知道我犯了一个愚蠢的错误,也许这可以帮助你。

    您声明客户的方式非常重要,可能因为我很着急,我在声明和要求变量时犯了一个愚蠢的错误。

    const client = require('@sendgrid/mail'); 
    

    应该是,const client = require('@sendgrid/client)

    Please have a look here

    【讨论】:

    • 你不应该把你的钥匙放在一张图片里。我假设(希望)你已经撤销了这些。
    猜你喜欢
    • 1970-01-01
    • 2018-05-03
    • 2020-07-12
    • 2020-07-14
    • 2017-11-22
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多