You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Sign up](https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=70160000000pqBb) for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content.
3
+
[Sign up][sparkpostsign up] for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content.
4
4
5
5
# Node.js Client Library
6
6
@@ -12,7 +12,7 @@ The official Node.js binding for your favorite [SparkPost APIs](https://develope
12
12
13
13
Before using this library, you must have:
14
14
15
-
* A shiny new SparkPost Account, [sign up for a new account](https://app.sparkpost.com/#/sign-up) or [login to SparkPost](https://app.sparkpost.com/)
15
+
* A shiny new SparkPost Account, [sign up for a new account][sparkpostsign up] or [login to SparkPost](https://app.sparkpost.com/)
16
16
* A valid SparkPost API Key. Check out our [Support Center](https://support.sparkpost.com/) for information on how to [create API keys](https://support.sparkpost.com/customer/portal/articles/1933377-create-api-keys)
17
17
18
18
## Installation
@@ -21,8 +21,10 @@ Before using this library, you must have:
21
21
npm install sparkpost
22
22
```
23
23
24
+
*Note: Node.js versions 0.10 and 0.12 are no longer supported. For versions < 4, please continue using [sparkpost v1.3.8](https://github.com/SparkPost/node-sparkpost/tree/1.3.8)*
*`options.uri` - can either be a full url or a path that is appended to `options.origin` used at initialization ([url.resolve](http://nodejs.org/api/url.html#url_url_resolve_from_to))
48
-
*`callback` - executed after task is completed. **required**
49
-
* standard `callback(err, data)`
50
-
*`err` - any error that occurred
51
-
*`data.res` - full response from request client
52
-
*`data.body` - payload from response
53
-
***get | post | put | delete(options, callback)**
59
+
*`options.debug` - setting to `true` includes full response from request client for debugging purposes
60
+
***get | post | put | delete(options[, callback])**
54
61
*`options` - see request options
55
-
*`callback` - see request options
56
62
* Request method will be overwritten and set to the same value as the name of these methods.
57
63
58
64
## Creating a SparkPost Client
@@ -91,25 +97,27 @@ var options = {
91
97
uri:'metrics/domains'
92
98
};
93
99
94
-
client.get(options, function(err, data) {
95
-
if(err) {
100
+
client.get(options)
101
+
.then(data=> {
102
+
console.log(data);
103
+
})
104
+
.catch(err=> {
96
105
console.log(err);
97
-
return;
98
-
}
99
-
100
-
console.log(data.body);
101
-
});
106
+
});
102
107
```
103
108
104
109
## Send An Email "Hello World" Example
105
-
Below is an example of how to send a simple email. Sending an email is known as a *transmission*. By using the send method on the transmissions service that's available from the SparkPost object you instatiate you can pass in a *transmissionBody* object with all the information relevant to the email being sent. The send method also takes a callback method that will let you know if the email was sent successful and if not information about the error that ocurred.
110
+
Below is an example of how to send a simple email. Sending an email is known as a *transmission*. By using the send
111
+
method on the transmissions service that's available from the SparkPost object you instantiate, you can pass in an
112
+
object with all the [transmission attributes](https://developers.sparkpost.com/api/transmissions#header-transmission-attributes)
113
+
relevant to the email being sent. The send method will return a promise that will let you know if the email was sent
114
+
successful and if not information about the error that occurred. If a callback is passed, it will be executed.
106
115
107
116
```javascript
108
117
var SparkPost =require('sparkpost');
109
-
varsp=newSparkPost('<YOUR API KEY>');
118
+
varclient=newSparkPost('<YOUR API KEY>');
110
119
111
-
sp.transmissions.send({
112
-
transmissionBody: {
120
+
client.transmissions.send({
113
121
content: {
114
122
from:'testing@sparkpostbox.com',
115
123
subject:'Hello, World!',
@@ -118,15 +126,15 @@ sp.transmissions.send({
118
126
recipients: [
119
127
{address:'<YOUR EMAIL ADDRESS>'}
120
128
]
121
-
}
122
-
}, function(err, res) {
123
-
if (err) {
129
+
})
130
+
.then(data=> {
131
+
console.log('Woohoo! You just sent your first mailing!');
132
+
console.log(data);
133
+
})
134
+
.catch(err=> {
124
135
console.log('Whoops! Something went wrong');
125
136
console.log(err);
126
-
} else {
127
-
console.log('Woohoo! You just sent your first mailing!');
128
-
}
129
-
});
137
+
});
130
138
```
131
139
132
140
## SparkPost API Resources Supported in Node Client Library
@@ -147,20 +155,20 @@ Click on the desired API to see usage and more information
147
155
## Development
148
156
149
157
### Setup
150
-
We use [Grunt](http://gruntjs.com/) for our task runner, so you will also have to install Grunt globally `npm install -g grunt-cli`
151
-
152
158
Run `npm install` inside the repository to install all the dev dependencies.
153
159
154
160
### Testing
155
-
Once all the dependencies are installed, you can execute the unit tests using `grunt test`
161
+
Once all the dependencies are installed, you can execute the unit tests using `npm test`
156
162
157
163
### Contributing
158
-
[Guidelines for adding issues](docs/ADDING_ISSUES.markdown)
164
+
[Guidelines for adding issues](docs/ADDING_ISSUES.md)
0 commit comments