使用 SendGrid 搜索联系人 API
Search Contacts with SendGrid API
https://sendgrid.api-docs.io/v3.0/contacts/search-contacts
我正在尝试搜索上面 SendGrids 文档中所示的联系人。在下面的正文部分,我想将硬编码的“andrew@gmail.com”更改为一个变量。例如 email = req.user.email;
正确的做法是什么?仅设置变量并放入 'email' 是行不通的。
var request = require("request");
var options = { method: 'POST',
url: 'https://api.sendgrid.com/v3/marketing/contacts/search',
headers:
{ 'content-type': 'application/json',
authorization: 'Bearer SG.key' },
body: { query: 'email LIKE \'andrew@gmail.com\' AND CONTAINS(list_ids, \'6bcc2d0c-ea17-41ba-a4a1-962badsasdas1\')' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
此处为 Twilio SendGrid 开发人员布道师。
尝试使用 string interpolation 使用反引号(作为额外的好处,意味着您不必转义单引号),如下所示:
const email = req.user.email;
const body = `email LIKE '${email}' AND CONTAINS(list_ids, '6bcc2d0c-ea17-41ba-a4a1-962badsasdas1')`;
const options = {
method: 'POST',
url: 'https://api.sendgrid.com/v3/marketing/contacts/search',
headers: {
'content-type': 'application/json',
authorization: 'Bearer SG.key'
},
body: { query: query },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
https://sendgrid.api-docs.io/v3.0/contacts/search-contacts
我正在尝试搜索上面 SendGrids 文档中所示的联系人。在下面的正文部分,我想将硬编码的“andrew@gmail.com”更改为一个变量。例如 email = req.user.email;
正确的做法是什么?仅设置变量并放入 'email' 是行不通的。
var request = require("request");
var options = { method: 'POST',
url: 'https://api.sendgrid.com/v3/marketing/contacts/search',
headers:
{ 'content-type': 'application/json',
authorization: 'Bearer SG.key' },
body: { query: 'email LIKE \'andrew@gmail.com\' AND CONTAINS(list_ids, \'6bcc2d0c-ea17-41ba-a4a1-962badsasdas1\')' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
此处为 Twilio SendGrid 开发人员布道师。
尝试使用 string interpolation 使用反引号(作为额外的好处,意味着您不必转义单引号),如下所示:
const email = req.user.email;
const body = `email LIKE '${email}' AND CONTAINS(list_ids, '6bcc2d0c-ea17-41ba-a4a1-962badsasdas1')`;
const options = {
method: 'POST',
url: 'https://api.sendgrid.com/v3/marketing/contacts/search',
headers: {
'content-type': 'application/json',
authorization: 'Bearer SG.key'
},
body: { query: query },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});