Skip to content

Commit cf910a3

Browse files
committed
modified send examples to use reqOpts
1 parent a221c57 commit cf910a3

File tree

7 files changed

+112
-100
lines changed

7 files changed

+112
-100
lines changed

docs/resources/transmissions.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,21 @@ This library provides easy access to the [Transmissions](https://www.sparkpost.c
2828
var SparkPost = require('sparkpost')
2929
, client = new SparkPost('YOUR API KEY');
3030

31-
var trans = {
32-
content: {}
31+
var reqObj = {
32+
transmissionBody: {
33+
campaignId: 'first-mailing',
34+
content: {
35+
36+
subject: 'First SDK Mailing',
37+
html: '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
38+
text: 'Congratulations, {{name}}!! You just sent your very first mailing!'
39+
}
40+
substitutionData: {name: 'YOUR FIRST NAME'},
41+
recipients: [{ address: { name: 'YOUR FULL NAME', email: 'YOUR EMAIL ADDRESS' } }]
42+
}
3343
};
3444

35-
// Set some metadata for your email
36-
trans.campaignId = 'first-mailing';
37-
trans.content.from = '[email protected]';
38-
trans.content.subject = 'First SDK Mailing';
39-
40-
// Add some content to your email
41-
trans.content.html = '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>';
42-
trans.content.text = 'Congratulations, {{name}}!! You just sent your very first mailing!';
43-
trans.substitutionData = {name: 'YOUR FIRST NAME'};
44-
45-
// Pick someone to receive your email
46-
trans.recipients = [{ address: { name: 'YOUR FULL NAME', email: 'YOUR EMAIL ADDRESS' } }];
47-
48-
// Send it off into the world!
49-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
45+
client.transmissions.send(reqObj, function(err, res) {
5046
if (err) {
5147
console.log('Whoops! Something went wrong');
5248
console.log(err);

examples/transmissions/mime_parts.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
recipients: [{ address: { email: '[email protected]' } }],
9-
content: {
10-
from: 'From Envelope <[email protected]>',
11-
subject: 'Example Email for MIME Parts',
12-
html: '<html><body><p>Hello World!</p></body></html>',
13-
text: 'Hello World!'
14-
},
15-
options: {
16-
open_tracking: true,
17-
click_tracking: true
7+
var reqObj = {
8+
transmissionBody: {
9+
recipients: [{ address: { email: '[email protected]' } }],
10+
content: {
11+
from: 'From Envelope <[email protected]>',
12+
subject: 'Example Email for MIME Parts',
13+
html: '<html><body><p>Hello World!</p></body></html>',
14+
text: 'Hello World!'
15+
},
16+
options: {
17+
open_tracking: true,
18+
click_tracking: true
19+
}
1820
}
1921
};
2022

21-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
23+
client.transmissions.send(reqObj, function(err, res) {
2224
if (err) {
2325
console.log(err);
2426
} else {

examples/transmissions/rfc822.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
recipients: [{address: {email: '[email protected]'}}],
9-
content: {
10-
email_rfc822: 'Content-Type: text/plain\nFrom: From Envelope <[email protected]>\nSubject: Example Email\n\nHello World'
7+
var reqObj = {
8+
transmissionBody: {
9+
recipients: [{address: {email: '[email protected]'}}],
10+
content: {
11+
email_rfc822: 'Content-Type: text/plain\nFrom: From Envelope <[email protected]>\nSubject: Example Email\n\nHello World'
12+
}
1113
}
1214
};
1315

14-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
16+
client.transmissions.send(reqObj, function(err, res) {
1517
if (err) {
1618
console.log(err);
1719
} else {

examples/transmissions/send_transmission_all_fields.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,58 @@ var key = "YOURAPIKEY"
44
, SparkPost = require("sparkpost")
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
options: {
9-
open_tracking: true,
10-
click_tracking: true
11-
},
12-
campaign_id: "christmas_campaign",
13-
return_path: "[email protected]",
14-
metadata: {
15-
user_type: "students"
16-
},
17-
substitution_data: {
18-
sender: "Big Store Team"
19-
},
20-
recipients: [
21-
{
22-
return_path: "[email protected]",
23-
address: {
24-
25-
name: "Wilma Flintstone"
7+
var reqOpts = {
8+
transmissionBody: {
9+
options: {
10+
open_tracking: true,
11+
click_tracking: true
12+
},
13+
campaign_id: "christmas_campaign",
14+
return_path: "[email protected]",
15+
metadata: {
16+
user_type: "students"
17+
},
18+
substitution_data: {
19+
sender: "Big Store Team"
20+
},
21+
recipients: [
22+
{
23+
return_path: "[email protected]",
24+
address: {
25+
26+
name: "Wilma Flintstone"
27+
},
28+
tags: [
29+
"greeting",
30+
"prehistoric",
31+
"fred",
32+
"flintstone"
33+
],
34+
metadata: {
35+
place: "Bedrock"
36+
},
37+
substitution_data: {
38+
customer_type: "Platinum"
39+
}
40+
}
41+
],
42+
content: {
43+
from: {
44+
name: "Fred Flintstone",
45+
2646
},
27-
tags: [
28-
"greeting",
29-
"prehistoric",
30-
"fred",
31-
"flintstone"
32-
],
33-
metadata: {
34-
place: "Bedrock"
47+
subject: "Big Christmas savings!",
48+
reply_to: "Christmas Sales <[email protected]>",
49+
headers: {
50+
"X-Customer-Campaign-ID": "christmas_campaign"
3551
},
36-
substitution_data: {
37-
customer_type: "Platinum"
38-
}
52+
text: "Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{user_type}}\n {{sender}}",
53+
html: "<p>Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n</p><p>Hurry, this offer is only to {{user_type}}\n</p><p>{{sender}}</p>"
3954
}
40-
],
41-
content: {
42-
from: {
43-
name: "Fred Flintstone",
44-
45-
},
46-
subject: "Big Christmas savings!",
47-
reply_to: "Christmas Sales <[email protected]>",
48-
headers: {
49-
"X-Customer-Campaign-ID": "christmas_campaign"
50-
},
51-
text: "Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n Hurry, this offer is only to {{user_type}}\n {{sender}}",
52-
html: "<p>Hi {{address.name}} \nSave big this Christmas in your area {{place}}! \nClick http://www.mysite.com and get huge discount\n</p><p>Hurry, this offer is only to {{user_type}}\n</p><p>{{sender}}</p>"
5355
}
5456
};
5557

56-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
58+
client.transmissions.send(reqOpts, function(err, res) {
5759
if (err) {
5860
console.log(err);
5961
} else {

examples/transmissions/stored_recipients_inline_content.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
listId: 'example-list',
9-
content: {
10-
from: 'From Envelope <[email protected]>',
11-
subject: 'Example Email for Stored List and Inline Content',
12-
html: '<html><body><p>Hello World</p></body></html>',
13-
text: 'Hello World!'
7+
var reqObj = {
8+
transmissionBody: {
9+
recipients: {
10+
listId: 'example-list'
11+
},
12+
content: {
13+
from: 'From Envelope <[email protected]>',
14+
subject: 'Example Email for Stored List and Inline Content',
15+
html: '<html><body><p>Hello World</p></body></html>',
16+
text: 'Hello World!'
17+
}
1418
}
1519
};
1620

17-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
21+
client.transmissions.send(req, function(err, res) {
1822
if (err) {
1923
console.log(err);
2024
} else {

examples/transmissions/stored_recipients_stored_content.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
listId: 'example-list',
9-
content: {
10-
from: 'From Envelope <[email protected]>',
11-
subject: 'Example Email for Stored List and Template',
12-
templateId: 'my-template'
7+
var reqOpts = {
8+
transmissionBody: {
9+
recipients: {
10+
listId: 'example-list'
11+
},
12+
content: {
13+
from: 'From Envelope <[email protected]>',
14+
subject: 'Example Email for Stored List and Template',
15+
templateId: 'my-template'
16+
}
1317
}
1418
};
1519

16-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
20+
client.transmissions.send(reqOpts, function(err, res) {
1721
if (err) {
1822
console.log(err);
1923
} else {

examples/transmissions/stored_template_send.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ var key = 'YOURAPIKEY'
44
, SparkPost = require('sparkpost')
55
, client = new SparkPost(key);
66

7-
var trans = {
8-
recipients: [{ address: { email: '[email protected]' } }],
9-
content: {
10-
templateId: 'my-template',
11-
from: 'From Envelope <[email protected]>',
12-
subject: 'Example Email for Stored Template'
7+
var reqOpts = {
8+
transmissionBody: {
9+
recipients: [{ address: { email: '[email protected]' } }],
10+
content: {
11+
templateId: 'my-template',
12+
from: 'From Envelope <[email protected]>',
13+
subject: 'Example Email for Stored Template'
14+
}
1315
}
1416
};
1517

16-
client.transmissions.send({transmissionBody: trans}, function(err, res) {
18+
client.transmissions.send(reqOpts, function(err, res) {
1719
if (err) {
1820
console.log(err);
1921
} else {

0 commit comments

Comments
 (0)