Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Syntax highlighting for examples with GFM

  • Loading branch information...
commit 7a31d70e1f5b32f3b13cc514cbb1485635fcb164 1 parent ece07ad
@gomfunkel authored
Showing with 141 additions and 127 deletions.
  1. +141 −127 README.md
View
268 README.md
@@ -42,29 +42,31 @@ The callback function for each API method gets one argument, an object with all
Example:
- var MailChimpAPI = require('mailchimp').MailChimpAPI;
-
- var apiKey = 'Your MailChimp API Key';
-
- try {
- var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
- } catch (error) {
- console.log('Error: ' + error);
- }
-
- api.campaigns({ start: 0, limit: 25 }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(JSON.stringify(data)); // Do something with your data!
- });
-
- api.campaignStats({ cid : '/* CAMPAIGN ID */' }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(JSON.stringify(data)); // Do something with your data!
- });
+«««javascript
+var MailChimpAPI = require('mailchimp').MailChimpAPI;
+
+var apiKey = 'Your MailChimp API Key';
+
+try {
+ var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
+} catch (error) {
+ console.log('Error: ' + error);
+}
+
+api.campaigns({ start: 0, limit: 25 }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(JSON.stringify(data)); // Do something with your data!
+});
+
+api.campaignStats({ cid : '/* CAMPAIGN ID */' }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(JSON.stringify(data)); // Do something with your data!
+});
+«««
### MailChimp Export API
@@ -78,23 +80,25 @@ The callback function for the only Export API method at the moment (_list_) gets
Example:
- var MailChimpExportAPI = require('mailchimp').MailChimpExportAPI;
-
- var apiKey = 'Your MailChimp API Key';
+«««javascript
+var MailChimpExportAPI = require('mailchimp').MailChimpExportAPI;
- try {
- var exportApi = new MailChimpExportAPI(apiKey, { version : '1.0', secure: false });
- } catch (error) {
- console.log('Error: ' + error);
- }
+var apiKey = 'Your MailChimp API Key';
+
+try {
+ var exportApi = new MailChimpExportAPI(apiKey, { version : '1.0', secure: false });
+} catch (error) {
+ console.log('Error: ' + error);
+}
+
+exportApi.list({ id : '/* LIST ID */' }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(data); // Do something with your data!
+});
+«««
- exportApi.list({ id : '/* LIST ID */' }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(data); // Do something with your data!
- });
-
### MailChimp Webhooks
_MailChimpWebhook_ takes one argument, an options object which can contain the following options:
@@ -113,21 +117,23 @@ You can register the following events. The callback function for each of these e
Example:
- var MailChimpWebhook = require('mailchimp').MailChimpWebhook;
-
- var webhook = new MailChimpWebhook();
-
- webhook.on('error', function (message) {
- console.log('Error: '+message);
- });
-
- webhook.on('subscribe', function (data, meta) {
- console.log(data.email+' subscribed to your newsletter!'); // Do something with your data!
- });
-
- webhook.on('unsubscribe', function (data, meta) {
- console.log(data.email+' unsubscribed from your newsletter!'); // Do something with your data!
- });
+«««javascript
+var MailChimpWebhook = require('mailchimp').MailChimpWebhook;
+
+var webhook = new MailChimpWebhook();
+
+webhook.on('error', function (message) {
+ console.log('Error: '+message);
+});
+
+webhook.on('subscribe', function (data, meta) {
+ console.log(data.email+' subscribed to your newsletter!'); // Do something with your data!
+});
+
+webhook.on('unsubscribe', function (data, meta) {
+ console.log(data.email+' unsubscribed from your newsletter!'); // Do something with your data!
+});
+«««
### MailChimp STS API
@@ -141,22 +147,24 @@ The callback function for each API method gets one argument, an object with all
Example:
- var MailChimpSTSAPI = require('mailchimp').MailChimpSTSAPI;
-
- var apiKey = 'Your MailChimp API Key';
+«««javascript
+var MailChimpSTSAPI = require('mailchimp').MailChimpSTSAPI;
- try {
- var stsApi = new MailChimpSTSAPI(apiKey, { version : '1.0', secure: false });
- } catch (error) {
- console.log('Error: ' + error);
- }
+var apiKey = 'Your MailChimp API Key';
- stsApi.VerifyEmailAdress({ email : '/* E-MAIL ADDRESS */' }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(data); // Do something with your data!
- });
+try {
+ var stsApi = new MailChimpSTSAPI(apiKey, { version : '1.0', secure: false });
+} catch (error) {
+ console.log('Error: ' + error);
+}
+
+stsApi.VerifyEmailAdress({ email : '/* E-MAIL ADDRESS */' }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(data); // Do something with your data!
+});
+«««
### MailChimp OAuth2
@@ -176,40 +184,42 @@ You can register the following events:
Example:
- var MailChimpOAuth = require('mailchimp').MailChimpOAuth;
- var MailChimpAPI = require('mailchimp').MailChimpAPI;
-
- var options = {
- clientId: 'Your MailChimp client id',
- clientSecret: 'Your MailChimp client secret',
- serverUri: 'http://www.example.com',
- redirectUri: 'http://www.example.com/successfulLogin.html'
- };
-
- var oauth = new MailChimpOAuth(options);
+«««javascript
+var MailChimpOAuth = require('mailchimp').MailChimpOAuth;
+var MailChimpAPI = require('mailchimp').MailChimpAPI;
+
+var options = {
+ clientId: 'Your MailChimp client id',
+ clientSecret: 'Your MailChimp client secret',
+ serverUri: 'http://www.example.com',
+ redirectUri: 'http://www.example.com/successfulLogin.html'
+};
+
+var oauth = new MailChimpOAuth(options);
+
+console.log(oauth.getAuthorizeUri()); // The MailChimp login URI the user needs to be sent to
+
+oauth.on('error', function (message) {
+ console.log('Error: '+message);
+});
+
+oauth.on('authed', function (apiKey) {
- console.log(oauth.getAuthorizeUri()); // The MailChimp login URI the user needs to be sent to
+ try {
+ var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
+ } catch (error) {
+ console.log('Error: ' + error);
+ }
- oauth.on('error', function (message) {
- console.log('Error: '+message);
- });
+ api.campaigns({ start: 0, limit: 25 }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(JSON.stringify(data)); // Do something with your data!
+ });
- oauth.on('authed', function (apiKey) {
-
- try {
- var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
- } catch (error) {
- console.log('Error: ' + error);
- }
-
- api.campaigns({ start: 0, limit: 25 }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(JSON.stringify(data)); // Do something with your data!
- });
-
- });
+});
+«««
### Mandrill API \*EXPERIMENTAL\*
@@ -227,41 +237,45 @@ The callback function for each API method gets one argument, an object with all
Example:
- var MandrillAPI = require('mailchimp').MandrillAPI;
-
- var apiKey = 'Your Mandrill API Key';
+«««javascript
+var MandrillAPI = require('mailchimp').MandrillAPI;
- try {
- var mandrill = new MandrillAPI(apiKey, { version : '1.0', secure: false });
- } catch (error) {
- console.log('Error: ' + error);
- }
+var apiKey = 'Your Mandrill API Key';
+
+try {
+ var mandrill = new MandrillAPI(apiKey, { version : '1.0', secure: false });
+} catch (error) {
+ console.log('Error: ' + error);
+}
+
+mandrill.tags_time_series({ tag : '/* TAGNAME */' }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(data); // Do something with your data!
+});
+«««
- mandrill.tags_time_series({ tag : '/* TAGNAME */' }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(data); // Do something with your data!
- });
-
A second way to use the Mandrill API is by using the `call` method. This method differentiates between the categories and methods of the Mandrill API more clearly and automatically converts dashes to underscores. The example above using the `call` method looks like the this:
- var MandrillAPI = require('mailchimp').MandrillAPI;
-
- var apiKey = 'Your Mandrill API Key';
+«««javascript
+var MandrillAPI = require('mailchimp').MandrillAPI;
- try {
- var mandrill = new MandrillAPI(apiKey, { version : '1.0', secure: false });
- } catch (error) {
- console.log('Error: ' + error);
- }
+var apiKey = 'Your Mandrill API Key';
- mandrill.call('tags', 'time-series', { tag : '/* TAGNAME */' }, function (data) {
- if (data.error)
- console.log('Error: '+data.error+' ('+data.code+')');
- else
- console.log(data); // Do something with your data!
- });
+try {
+ var mandrill = new MandrillAPI(apiKey, { version : '1.0', secure: false });
+} catch (error) {
+ console.log('Error: ' + error);
+}
+
+mandrill.call('tags', 'time-series', { tag : '/* TAGNAME */' }, function (data) {
+ if (data.error)
+ console.log('Error: '+data.error+' ('+data.code+')');
+ else
+ console.log(data); // Do something with your data!
+});
+«««
## License
Please sign in to comment.
Something went wrong with that request. Please try again.