1 00:00:04,580 --> 00:00:07,410 Now the process to install us on a mac is very similar. 2 00:00:07,410 --> 00:00:12,810 You simply download the software and install it like any other software, so you download and install 3 00:00:12,810 --> 00:00:14,340 the DMG file. 4 00:00:14,610 --> 00:00:17,820 In this example, I've got some queries saved. 5 00:00:18,610 --> 00:00:20,470 Now, I've told you, I'm going to show you this manually. 6 00:00:20,500 --> 00:00:25,970 The only reason to save the queries is I don't have to manually type them and perhaps make mistakes. 7 00:00:25,990 --> 00:00:31,840 So to save on the recording and save your time, I've prebuilt this, but here are all the steps. 8 00:00:32,409 --> 00:00:36,700 The first thing we need when communicating with the DNA center server is a token. 9 00:00:36,730 --> 00:00:40,810 There are different ways to implement authentication with a rest API. 10 00:00:40,840 --> 00:00:45,250 In this example, they're using a token, which is a very popular way of doing it. 11 00:00:45,340 --> 00:00:51,910 The idea with the token is I will authenticate to the server using a username and password. 12 00:00:52,030 --> 00:00:57,220 A token will be given to me and that token is valid for a period of time. 13 00:00:57,220 --> 00:01:02,740 And every time I make an API call, I send the token to the server to be authenticated. 14 00:01:02,740 --> 00:01:08,220 In other words, to allow me to run the command against the rest API. 15 00:01:08,230 --> 00:01:11,050 So first thing username and password needs to be sent. 16 00:01:11,080 --> 00:01:17,110 Get back a token subsequent API calls, use the token rather than sending the username and password 17 00:01:17,110 --> 00:01:18,730 in the API call. 18 00:01:19,780 --> 00:01:20,000 Okay. 19 00:01:20,080 --> 00:01:21,340 So this is the URL. 20 00:01:21,370 --> 00:01:28,540 To get the token, i need to use a username of dev net user password is cisco 1 to 3 exclamation. 21 00:01:28,540 --> 00:01:32,080 It's a post and then we need to copy back the token. 22 00:01:32,560 --> 00:01:41,710 So as an example, if I try to use a get to get information from the DNA center server and I click send, 23 00:01:41,890 --> 00:01:44,380 I'm getting token has expired. 24 00:01:44,650 --> 00:01:48,700 Before I can get information from the server, I need to get a token. 25 00:01:49,450 --> 00:01:50,410 It's not a get. 26 00:01:50,440 --> 00:01:51,580 It's a post. 27 00:01:52,240 --> 00:01:56,500 Post once again, allows me to create data structures and variables. 28 00:01:58,310 --> 00:02:00,920 So your role is this? 29 00:02:00,950 --> 00:02:03,230 I've put that in the PowerPoint slide once again. 30 00:02:04,030 --> 00:02:13,510 Authorisation username is definite user password is Cisco 1 to 3 exclamation mark that's under the authorization 31 00:02:13,510 --> 00:02:14,200 tab. 32 00:02:14,290 --> 00:02:17,410 So if you were creating a new API call, you click on. 33 00:02:17,410 --> 00:02:21,520 Plus at the top you specify what you're using. 34 00:02:21,520 --> 00:02:23,250 Once again, it's a post. 35 00:02:23,590 --> 00:02:29,920 Specify the URL, which I've got in the PowerPoint presentation, so I'm going to paste that in. 36 00:02:31,560 --> 00:02:34,800 Notice we want to get a token from the server. 37 00:02:35,550 --> 00:02:40,260 Authorization is basic authentication. 38 00:02:40,290 --> 00:02:47,190 Different types of authorization are available here, including Birra, Token Digest, authentication, 39 00:02:47,370 --> 00:02:50,700 oath, a signature and many others. 40 00:02:51,270 --> 00:02:53,730 But basic authentication. 41 00:02:55,100 --> 00:02:56,400 Username is dev. 42 00:02:56,420 --> 00:02:57,770 Net user. 43 00:02:59,090 --> 00:03:00,830 Password is Cisco. 44 00:03:00,860 --> 00:03:02,870 One, two, three, exclamation. 45 00:03:03,470 --> 00:03:04,160 So, Cisco. 46 00:03:04,190 --> 00:03:05,900 One, two, three, exclamation. 47 00:03:06,470 --> 00:03:10,610 Once you've done that, you can click send and we get a token back. 48 00:03:11,610 --> 00:03:15,660 So once you've got your token, you need to copy this token. 49 00:03:16,470 --> 00:03:22,910 So copy that token because we now going to use that for subsequent API calls. 50 00:03:22,920 --> 00:03:28,890 So as an example, if we want to get information from the server, we need to use that token. 51 00:03:29,650 --> 00:03:33,160 So let's get a list of devices from DNA Center. 52 00:03:34,600 --> 00:03:44,650 Now once again looking at the API documentation, this API call get DNA intent API v one network device 53 00:03:44,770 --> 00:03:47,380 gives us a list of devices. 54 00:03:47,470 --> 00:03:54,790 So we told that it returns a list of network devices based on filter criteria such as IP address or 55 00:03:54,790 --> 00:03:55,780 something else. 56 00:03:55,870 --> 00:04:04,030 So we can filter this down or simply get a list of devices that have registered with DNA center. 57 00:04:04,120 --> 00:04:10,060 Now, remember, DNA Center is talking down to network devices using different protocols on the southbound 58 00:04:10,060 --> 00:04:10,690 API. 59 00:04:10,720 --> 00:04:13,840 We are now querying the northbound API. 60 00:04:14,730 --> 00:04:19,290 So we are using the northbound API to query DNA center. 61 00:04:20,560 --> 00:04:21,010 CQ. 62 00:04:21,019 --> 00:04:29,860 I've got a prebuilt API call, but again, let's create that manually so that you can see the full process. 63 00:04:30,720 --> 00:04:33,460 What I need is the euro. 64 00:04:34,440 --> 00:04:36,330 So this is a get. 65 00:04:37,790 --> 00:04:38,960 And the URL. 66 00:04:39,320 --> 00:04:43,790 Just click on the little plus shear if you want to create a new API call. 67 00:04:44,210 --> 00:04:46,010 So it's a get. 68 00:04:46,040 --> 00:04:48,500 Here's the URL or the URI. 69 00:04:48,770 --> 00:04:51,320 We need to go to headers. 70 00:04:52,010 --> 00:04:55,850 So headers here and we need to specify a key. 71 00:04:55,850 --> 00:05:00,170 The key that we're going to create is content type. 72 00:05:00,620 --> 00:05:02,780 So you need to specify content type. 73 00:05:03,080 --> 00:05:07,850 And the key here is application JSON. 74 00:05:10,220 --> 00:05:13,850 And then we need to specify x auth token. 75 00:05:14,300 --> 00:05:20,530 This kind of stuff is going to basically be sent to the server when we make the API call. 76 00:05:20,540 --> 00:05:22,130 So we're using rest API. 77 00:05:22,160 --> 00:05:24,110 Think of it kind of like https. 78 00:05:24,260 --> 00:05:30,110 We're making we're sending HTTPS information to the server saying get once again, it's kind of as an 79 00:05:30,110 --> 00:05:36,490 analogy with a web page where I send a get and then I get back a web page, but I'm using an API and 80 00:05:36,500 --> 00:05:38,990 I'm getting back other information from the server. 81 00:05:39,410 --> 00:05:44,120 We're doing this manually, but once again, I'll show you later how to use a Python script to pull 82 00:05:44,120 --> 00:05:46,670 this kind of information out of a router as an example. 83 00:05:47,540 --> 00:05:49,220 So here we need our token. 84 00:05:49,520 --> 00:05:54,710 So we need to copy that token from the previous post statement. 85 00:05:55,630 --> 00:05:57,970 And I need to put my token in here. 86 00:05:58,330 --> 00:06:01,630 Just make sure that you don't copy the inverted commas. 87 00:06:01,630 --> 00:06:04,720 So copy only the API. 88 00:06:06,540 --> 00:06:06,810 Okay. 89 00:06:06,810 --> 00:06:14,610 So we've said it to get we've got our URL, we've set the content type to application JSON, we've set 90 00:06:14,610 --> 00:06:18,330 the X auth token to the token that we received. 91 00:06:18,960 --> 00:06:19,800 Click send. 92 00:06:21,540 --> 00:06:22,540 And there you go. 93 00:06:22,560 --> 00:06:28,860 We've now made an API call to a Cisco DNA center server using the northbound API. 94 00:06:28,890 --> 00:06:34,950 So northbound to the controller, it's talking to network devices using the southbound API. 95 00:06:35,670 --> 00:06:41,310 Here are some network devices that have registered with DNA center. 96 00:06:41,730 --> 00:06:45,120 So as an example, we've got this Cisco ASR router. 97 00:06:45,390 --> 00:06:49,440 Scrolling down, we've got this catalyst switch scrolling down. 98 00:06:49,440 --> 00:06:50,760 Now the catalyst switch. 99 00:06:52,870 --> 00:06:54,730 And once again, another switch. 100 00:06:54,970 --> 00:06:58,150 Now what you can do is edit that API. 101 00:06:58,720 --> 00:06:59,860 Remember? 102 00:07:00,630 --> 00:07:06,930 What we've done here is we've connected to this part of the URL. 103 00:07:07,050 --> 00:07:11,220 But what we can do is specify some parameters. 104 00:07:11,490 --> 00:07:14,700 So we could specify as an example the type. 105 00:07:15,510 --> 00:07:16,770 How do I know that? 106 00:07:16,770 --> 00:07:19,950 Because yeah, we've got type and a name. 107 00:07:20,610 --> 00:07:22,950 So I could type if I wanted to. 108 00:07:23,280 --> 00:07:31,080 Question mark type equals Cisco ASR 1001 exe router. 109 00:07:31,110 --> 00:07:32,520 That name, basically. 110 00:07:33,030 --> 00:07:39,090 If I click send, all I get is the information for that router. 111 00:07:39,450 --> 00:07:41,190 Not all the other riders. 112 00:07:41,430 --> 00:07:43,290 I could specify software type. 113 00:07:43,290 --> 00:07:47,490 So rather than doing it like that type software. 114 00:07:48,240 --> 00:07:51,000 Type equals EOS XY. 115 00:07:51,060 --> 00:07:55,710 Now it's remembered what I've typed previously, so that's why it's auto filling this in here. 116 00:07:55,920 --> 00:07:58,620 In your case, you would have to manually type that. 117 00:07:58,740 --> 00:08:04,830 But if I click send now I get the ASR rotor, but I also see the catalyst switch. 118 00:08:05,970 --> 00:08:07,440 And other devices. 119 00:08:07,440 --> 00:08:12,540 So it's basically pulled back all the devices that are using. 120 00:08:13,730 --> 00:08:14,900 EOS xy. 121 00:08:16,290 --> 00:08:20,820 Now you could specify something like Mac address, so I don't think I've used that previously. 122 00:08:20,820 --> 00:08:30,630 So let's say Mac address equals and copy this notice we're using structured data here sent. 123 00:08:31,080 --> 00:08:33,000 We only get to that ASR. 124 00:08:33,030 --> 00:08:35,159 We don't get the other devices. 125 00:08:35,159 --> 00:08:37,950 Notice it's ended here at line 46. 126 00:08:37,950 --> 00:08:46,800 But if I removed that and simply looked at all devices, I get all the devices, we've got 169 lines 127 00:08:46,800 --> 00:08:48,420 of output that's been returned. 128 00:08:48,990 --> 00:08:51,480 You could do something like this, say platform. 129 00:08:51,480 --> 00:08:53,960 So simply put a question mark at the end there. 130 00:08:54,510 --> 00:08:59,520 Remove this information that's not required equals what we're looking for. 131 00:08:59,550 --> 00:09:01,710 Click send and there we go. 132 00:09:01,710 --> 00:09:04,980 We only get back that switch. 133 00:09:05,930 --> 00:09:06,980 So there you go. 134 00:09:07,010 --> 00:09:09,380 That's an example of using a rest API. 135 00:09:09,410 --> 00:09:16,640 We did a post to get back our token, so we retrieved a token and then we used gets to retrieve information 136 00:09:16,640 --> 00:09:18,140 from the server. 137 00:09:18,530 --> 00:09:25,670 Again, how do you know what you should be using that's available in the rest API documentation? 138 00:09:25,910 --> 00:09:28,430 So as an example, a authentication. 139 00:09:28,430 --> 00:09:31,070 It's a post to get the authentication. 140 00:09:32,690 --> 00:09:38,270 The developers would have written this API, they build the API. 141 00:09:38,360 --> 00:09:42,930 We told the code when we successful or when it's invalid credentials. 142 00:09:42,950 --> 00:09:50,240 So as an example, if I went back here and try to do a post and I put the wrong password in, I would 143 00:09:50,240 --> 00:09:52,400 get authentication as failed. 144 00:09:52,400 --> 00:09:54,770 Please provide valid credentials. 145 00:09:54,890 --> 00:09:59,480 Notice the code is for one unauthorized. 146 00:09:59,510 --> 00:10:00,900 Put the right password in. 147 00:10:00,920 --> 00:10:01,720 Click send. 148 00:10:01,730 --> 00:10:06,920 We get the token back and it'll be a different token every time you make this API call. 149 00:10:07,220 --> 00:10:10,850 A token is valid for a period of time that they decide. 150 00:10:11,360 --> 00:10:14,390 So it really depends on what the developer has decided to do. 151 00:10:15,230 --> 00:10:19,910 Again, this get statement allows me to get devices. 152 00:10:20,150 --> 00:10:23,020 If I made a mistake, I would get errors. 153 00:10:23,030 --> 00:10:25,040 So 200 is success. 154 00:10:25,280 --> 00:10:27,470 Let's go back over here. 155 00:10:28,280 --> 00:10:31,010 Click Send notice 200. 156 00:10:31,250 --> 00:10:32,600 Everything is good. 157 00:10:32,600 --> 00:10:34,340 So we made no mistakes. 158 00:10:34,700 --> 00:10:38,450 But if I change this to, let's say, network device. 159 00:10:38,450 --> 00:10:40,730 So I broke the API. 160 00:10:40,760 --> 00:10:45,350 Your role here, I'm getting 404 error not found. 161 00:10:45,740 --> 00:10:51,080 Now to help you with your errors, I've put some errors in this PowerPoint presentation. 162 00:10:51,290 --> 00:10:53,540 So 200 Life is good. 163 00:10:53,990 --> 00:10:59,320 Just demonstrated that four one is unauthorized, token is not used. 164 00:10:59,330 --> 00:11:05,000 So again, if I deleted this token, so let's delete that token. 165 00:11:05,690 --> 00:11:08,270 So I'll cut it and click send. 166 00:11:08,600 --> 00:11:12,890 We've got a41 error unauthorized bad token. 167 00:11:13,310 --> 00:11:15,680 Put that in send. 168 00:11:15,680 --> 00:11:22,490 We're getting technical name network devices not found for oh four because this is wrong. 169 00:11:22,790 --> 00:11:26,480 It has to be network hyphen or dash device. 170 00:11:27,500 --> 00:11:29,840 Now we get 200, everything is good. 171 00:11:30,320 --> 00:11:36,110 So you can see very easily what error messages have been returned if you made a mistake. 172 00:11:36,530 --> 00:11:37,850 Okay, here's a 400 error. 173 00:11:37,880 --> 00:11:41,800 Once again, if I say network device 1 to 3. 174 00:11:41,810 --> 00:11:43,550 So once again, if I do that. 175 00:11:43,550 --> 00:11:44,300 So I've made it. 176 00:11:44,300 --> 00:11:45,110 One, two, three. 177 00:11:45,110 --> 00:11:45,650 Here. 178 00:11:46,800 --> 00:11:49,470 Click Send four bad request. 179 00:11:51,020 --> 00:11:56,300 And we're told one, two, three is not a valid UUID of a device. 180 00:11:56,570 --> 00:12:01,370 If I did this notice I removed the question mark by mistake. 181 00:12:01,370 --> 00:12:03,470 We told invalid characters. 182 00:12:03,920 --> 00:12:06,410 So this needs to have a question mark there. 183 00:12:07,130 --> 00:12:08,120 Click send. 184 00:12:08,120 --> 00:12:10,430 Now we get to the correct data back. 185 00:12:10,940 --> 00:12:13,650 Four four is probably one of the most famous ones that you've seen. 186 00:12:13,670 --> 00:12:17,810 Here's a screenshot of me going to Cisco's website and just typing some random stuff. 187 00:12:17,840 --> 00:12:18,800 So let's do that. 188 00:12:18,800 --> 00:12:21,080 Go to Cisco dot com and type. 189 00:12:21,080 --> 00:12:25,940 Just some random nonsense notice for for error. 190 00:12:25,970 --> 00:12:27,760 That page doesn't exist. 191 00:12:27,770 --> 00:12:30,110 So you might have seen this many times on the internet. 192 00:12:30,440 --> 00:12:32,750 We could do something similar with the rest API. 193 00:12:33,080 --> 00:12:37,460 So once again, I'll specify a network device like that for for error. 194 00:12:37,460 --> 00:12:43,490 Not found very common error when you've made a mistake with your URL. 195 00:12:43,970 --> 00:12:47,950 Now you may be thinking, but David, I could just use a CLI to do this. 196 00:12:47,960 --> 00:12:49,660 Just remember where we going? 197 00:12:49,670 --> 00:12:51,830 This is just the initial baby steps. 198 00:12:51,950 --> 00:13:00,260 I want to show you how you can query an API, how you can get information back using a visual application. 199 00:13:00,260 --> 00:13:05,510 This is a great application for testing the API, getting used to the API, making sure that everything 200 00:13:05,510 --> 00:13:08,000 works properly and then you can put it into code. 201 00:13:08,770 --> 00:13:14,770 I'm going to show you this Python script once again where I run a script on my local computer and query 202 00:13:14,860 --> 00:13:20,610 a API on a Cisco router, iSCSI rod in this case and get information back. 203 00:13:20,620 --> 00:13:24,460 So just remember where we going, baby steps learn. 204 00:13:24,880 --> 00:13:28,120 When you write in the beginning you learned enable, you learn confetti. 205 00:13:28,120 --> 00:13:31,660 But as you get more and more confident, you'll learn more and more complex things. 206 00:13:31,660 --> 00:13:32,740 Same thing here. 207 00:13:32,740 --> 00:13:37,480 You don't have to learn Python for the exam, but just remember, that's where we going. 208 00:13:37,810 --> 00:13:43,060 We're using this tool to learn about the API and learning how to interact with the API, but that's 209 00:13:43,060 --> 00:13:44,380 not where we want to end.