1 00:00:00,310 --> 00:00:04,990 Now that you've learned how the API works, let's talk about how to make API calls. 2 00:00:04,990 --> 00:00:09,010 One of our most frequently used API calls is the subscribe call. 3 00:00:09,010 --> 00:00:12,270 Subscribing new members to a list in your MailChimp account is an essential part of 4 00:00:12,270 --> 00:00:16,270 setting up whether you're building a custom sign up form, connecting a third 5 00:00:16,270 --> 00:00:20,749 party CRM to MailChimp, or just syncing an existing database of emails. 6 00:00:22,030 --> 00:00:25,190 Here's everything you'll need to make your API calls. 7 00:00:25,190 --> 00:00:27,730 First, you'll need a MailChimp API key. 8 00:00:27,730 --> 00:00:29,290 We've gone over how to create a new key and 9 00:00:29,290 --> 00:00:31,740 where to get it, if you don't have it handy. 10 00:00:31,740 --> 00:00:34,300 Next, you'll need a MailChimp list ID. 11 00:00:34,300 --> 00:00:38,150 A list ID can be gathered via the API or through the application. 12 00:00:38,150 --> 00:00:39,760 More on this in a second. 13 00:00:39,760 --> 00:00:42,280 You'll also need your new subscriber's email address. 14 00:00:42,280 --> 00:00:44,780 In order to add a new member to a list in MailChimp, 15 00:00:44,780 --> 00:00:46,930 they have to have a unique email address. 16 00:00:46,930 --> 00:00:49,650 Finally, you also have the option to pass in merge field or 17 00:00:49,650 --> 00:00:53,510 merge tag information like first name and last name. 18 00:00:53,510 --> 00:00:55,720 This is subscriber specific information and 19 00:00:55,720 --> 00:00:58,920 can be recalled dynamically in an email campaign. 20 00:00:58,920 --> 00:01:02,730 And here's the workflow we'll use, first we'll make a get request to the list 21 00:01:02,730 --> 00:01:05,600 endpoint, and get all of our list information. 22 00:01:05,600 --> 00:01:08,990 Then we'll make a second get request to the specific list 23 00:01:08,990 --> 00:01:11,090 to see that list information. 24 00:01:11,090 --> 00:01:14,720 Then we'll make a get request to the list slash list ID 25 00:01:14,720 --> 00:01:18,120 slash members endpoint to view the existing subscribers. 26 00:01:18,120 --> 00:01:22,800 And finally, we'll make a post request to the list slash list ID slash member's 27 00:01:22,800 --> 00:01:27,350 endpoint, with information about the new subscriber and adding them to the list. 28 00:01:27,350 --> 00:01:30,120 This specific workflow won't be necessary every time. 29 00:01:30,120 --> 00:01:33,380 You'll make a few extra calls to get familiar with the MailChimp API and 30 00:01:33,380 --> 00:01:34,490 get the information you need. 31 00:01:35,590 --> 00:01:37,320 Since you already have your API key for 32 00:01:37,320 --> 00:01:40,610 this account, look at the list where you want to subscribe the new member. 33 00:01:41,620 --> 00:01:45,770 Within MailChimp, each list is treated as its own separate entity, and 34 00:01:45,770 --> 00:01:47,230 uniquely identified with its ID. 35 00:01:47,230 --> 00:01:51,020 There are a couple ways to find the list ID. 36 00:01:51,020 --> 00:01:53,450 To view your list ID within a MailChimp account, 37 00:01:53,450 --> 00:01:55,180 click on the list tab in the navigation bar. 38 00:01:57,300 --> 00:02:01,090 Find the list you wanna use and in the settings drawer choose Settings. 39 00:02:02,340 --> 00:02:06,561 At the bottom of the settings page you'll see your list unique ID. 40 00:02:06,561 --> 00:02:09,961 You can also find this information under list name & defaults. 41 00:02:12,281 --> 00:02:16,030 Alternatively, if you're building an app or just writing a script, 42 00:02:16,030 --> 00:02:20,890 you may want a more programmatic way to go about finding your list and their IDs. 43 00:02:20,890 --> 00:02:24,340 That's where the MailChimp API does the heavy lifting for you. 44 00:02:24,340 --> 00:02:27,010 With a get request you can retrieve a collection of 45 00:02:27,010 --> 00:02:28,310 lists within a MailChimp account. 46 00:02:30,280 --> 00:02:34,770 For all API calls you'll need an API key to tell MailChimp who you are. 47 00:02:34,770 --> 00:02:37,520 However, depending on what sort of information you're sending or 48 00:02:37,520 --> 00:02:41,310 receiving, you may need to point towards specific resources or 49 00:02:41,310 --> 00:02:42,779 include additional parameters. 50 00:02:44,830 --> 00:02:47,830 For instance, if you wanted to create a new campaign, you'd need to send 51 00:02:47,830 --> 00:02:53,090 information about the subject line, from address, and actual HTML content. 52 00:02:53,090 --> 00:02:55,830 If you just wanted to get a list of your existing campaigns, 53 00:02:55,830 --> 00:02:57,290 you don't need all of that information. 54 00:02:58,620 --> 00:03:01,620 In short, it's always worth having a look at the documentation 55 00:03:01,620 --> 00:03:04,240 to see what's required for a particular API call. 56 00:03:05,510 --> 00:03:08,230 If all you need is to get information about your lists, 57 00:03:08,230 --> 00:03:11,700 the only thing that's required is your MailChimp API key. 58 00:03:11,700 --> 00:03:14,090 If you're using one of MailChimp's API wrappers, 59 00:03:14,090 --> 00:03:17,400 the wrapper handles the interaction with MailChimp behind the scenes. 60 00:03:17,400 --> 00:03:20,840 Curl, on the other hand, means you are going to do everything manually. 61 00:03:20,840 --> 00:03:25,030 This includes requesting the correct URL, making sure all of your parameters 62 00:03:25,030 --> 00:03:28,820 are included and valid, and using the correct type of HTTP request. 63 00:03:30,180 --> 00:03:33,230 For this course, you'll be using terminal for Mac or 64 00:03:33,230 --> 00:03:36,740 command prompt on Windows to make curl requests. 65 00:03:36,740 --> 00:03:39,250 If you're more comfortable with another programming language, 66 00:03:39,250 --> 00:03:42,860 curl is universal enough that you should be able to find a suitable library for 67 00:03:42,860 --> 00:03:44,620 your language of choice. 68 00:03:44,620 --> 00:03:49,190 Our API wrappers aim to simplify the process for a number of languages as well. 69 00:03:49,190 --> 00:03:51,350 To get started with Curl, open up terminal. 70 00:03:52,390 --> 00:03:56,220 Curl help to make web requests without having to load up a browser like Chrome. 71 00:03:56,220 --> 00:03:59,220 Instead, you can make a get request by putting the following into your 72 00:03:59,220 --> 00:04:00,670 terminal window. 73 00:04:00,670 --> 00:04:03,870 You'll use the command curl followed by the URL you're requesting. 74 00:04:04,910 --> 00:04:08,370 If we wanted to make get request for your MailChimp list, we'd use this format. 75 00:04:08,370 --> 00:04:12,750 We'll start with curl and then add in our default API URL, 76 00:04:12,750 --> 00:04:18,108 which is https://us whatever your data center is. 77 00:04:18,108 --> 00:04:24,369 .Api.mailchimp.com/3.0/lists. 78 00:04:24,369 --> 00:04:28,565 Where the US portion of the URL is your specific data center. 79 00:04:28,565 --> 00:04:32,190 3.0 is the version of the API we're using, and 80 00:04:32,190 --> 00:04:35,490 lists is a specific resource that we're requesting. 81 00:04:35,490 --> 00:04:39,290 Before you make this request though, you need to let MailChimp know who you are and 82 00:04:39,290 --> 00:04:40,980 which account you wanna ask about. 83 00:04:40,980 --> 00:04:44,360 If you don't include an API key, MailChimp will send you back an error. 84 00:04:46,820 --> 00:04:50,150 You can't just throw an API key anywhere though, because MailChimp is looking in 85 00:04:50,150 --> 00:04:53,200 a very specific place for this information, instead, 86 00:04:53,200 --> 00:04:56,990 you'll need to create an authorization header with your curl request. 87 00:04:56,990 --> 00:04:59,690 To add a header you add an argument to your curl request, 88 00:04:59,690 --> 00:05:03,450 and then in quotations marks fill in the details about your header. 89 00:05:03,450 --> 00:05:07,510 In this case we'll start with curl, -H for header, and 90 00:05:07,510 --> 00:05:11,911 then in quotation marks we'll add authorization:apikey, 91 00:05:11,911 --> 00:05:17,000 which tells us the type of authorization, and then are actual API key. 92 00:05:18,340 --> 00:05:23,770 And then we'll include our URL to the list end point, 93 00:05:23,770 --> 00:05:32,239 https://us10.api.mailchimp.com/3.0/lists. 94 00:05:32,239 --> 00:05:37,120 Now you can successfully run this curl request for your MailChimp email list. 95 00:05:37,120 --> 00:05:38,260 Depending on your account and 96 00:05:38,260 --> 00:05:42,240 how many lists you have, you should see a JSON return with your list information. 97 00:05:43,300 --> 00:05:46,580 Looking at the docs, you can get a feel for what data is being returned and 98 00:05:46,580 --> 00:05:48,600 where you might be able to locate it. 99 00:05:48,600 --> 00:05:51,470 As mentioned before, you're looking specifically for a list ID. 100 00:05:51,470 --> 00:05:55,500 You may notice that there are two possible return parameters 101 00:05:55,500 --> 00:05:57,360 that sound like they may be a match. 102 00:05:57,360 --> 00:05:58,460 ID, and web ID. 103 00:05:59,490 --> 00:06:03,820 The web ID parameter is all numbers, and it's used within the application. 104 00:06:03,820 --> 00:06:07,900 Unfortunately, this doesn't uniquely identify a list across all of MailChimp. 105 00:06:07,900 --> 00:06:10,320 But the ID value does. 106 00:06:10,320 --> 00:06:14,650 No two lists in MailChimp will have the same ID value, so that's the one you want. 107 00:06:14,650 --> 00:06:17,827 ID is referred to as list ID in the application. 108 00:06:17,827 --> 00:06:21,650 Lists ID tells us which specific list you'll be sending or 109 00:06:21,650 --> 00:06:22,840 pulling information from. 110 00:06:23,908 --> 00:06:26,340 If you wanna get information about a specific list, 111 00:06:26,340 --> 00:06:30,670 you can add an additional parameter to pull information for that list. 112 00:06:30,670 --> 00:06:33,080 You'll make a get request to the specific list. 113 00:06:34,080 --> 00:06:36,160 To get information about a specific list, 114 00:06:36,160 --> 00:06:39,400 you'll append the list unique ID to the end of the curl request. 115 00:06:39,400 --> 00:06:43,850 Picking up with our previous curl request we have the curl command, 116 00:06:43,850 --> 00:06:47,160 our authorization header, and then our list URL. 117 00:06:47,160 --> 00:06:52,360 Now we just add the list unique ID to the end of the URL, and 118 00:06:52,360 --> 00:06:54,190 we should see that list returned. 119 00:06:54,190 --> 00:06:56,460 Instead of getting information about all of the lists and 120 00:06:56,460 --> 00:06:58,960 sorting through to find our match, this tells MailChimp, 121 00:06:58,960 --> 00:07:01,980 we just wanna look at data for a very specific list. 122 00:07:01,980 --> 00:07:04,790 You can get general data of about each list in your MailChimp account 123 00:07:04,790 --> 00:07:08,040 by swapping out the ID portion at the end of the URL. 124 00:07:08,040 --> 00:07:11,370 Great, now you have the information you need for your list. 125 00:07:11,370 --> 00:07:14,440 But what other information that's provided that may be helpful? 126 00:07:14,440 --> 00:07:15,950 Check out your documentation and 127 00:07:15,950 --> 00:07:19,610 see if you can pick out some interesting values that you return with that API call.