1 00:00:05,430 --> 00:00:13,830 In this example, i'm running an ubuntu 18 zero for three virtual machine in VMware Fusion on my mac. 2 00:00:13,980 --> 00:00:22,650 Now you could do it directly on a mac, but I'm going to do it in a boon punto so that if you're using 3 00:00:22,650 --> 00:00:28,020 a Windows machine, I would suggest you run an open door shell or run an ubuntu VM or something. 4 00:00:28,620 --> 00:00:31,830 Seriously, linux is the way to go, so just learn Linux. 5 00:00:32,189 --> 00:00:38,070 So I'm going to do this by creating a file called XY py. 6 00:00:38,820 --> 00:00:44,580 In a previous video I showed you how to install Python on ubuntu, so I'm assuming that's already done. 7 00:00:44,940 --> 00:00:48,840 What I've done here is created a script that imports requests. 8 00:00:48,840 --> 00:00:54,810 Requests is a great way to interact with a web interface such as a rest API. 9 00:00:55,020 --> 00:00:59,370 So again, rather than reinventing the wheel, I'm just going to import that library. 10 00:00:59,370 --> 00:01:01,920 And then you'll see that my code is very simple. 11 00:01:02,830 --> 00:01:06,250 I'm going to allow self signed certificates. 12 00:01:06,250 --> 00:01:10,480 So if you don't do this, it'll fail once again, just like it would in Postman. 13 00:01:10,600 --> 00:01:15,580 So I'm going to add this so that it ignores self signed certificates, basically accepts them. 14 00:01:16,210 --> 00:01:18,010 Here are our credentials. 15 00:01:18,160 --> 00:01:23,530 So I'll copy that to my Ubuntu computer paste that in. 16 00:01:24,340 --> 00:01:25,900 That's the first part of the code. 17 00:01:26,020 --> 00:01:29,620 Second part of the code is notice the URL. 18 00:01:29,920 --> 00:01:34,810 This is exactly the same URL that we used in Postman. 19 00:01:35,110 --> 00:01:36,610 It's this URL. 20 00:01:36,760 --> 00:01:38,200 It's exactly this URL. 21 00:01:38,860 --> 00:01:41,090 But I've got that in a Python script. 22 00:01:41,110 --> 00:01:44,080 Now notice the headers here. 23 00:01:44,080 --> 00:01:50,770 We've got content type application accept application yangu data JSON. 24 00:01:51,190 --> 00:01:54,490 That is the same as here. 25 00:01:54,820 --> 00:02:03,490 Now, as I said, you can get away just using except but for a post I had to use accept and content 26 00:02:03,490 --> 00:02:04,030 type. 27 00:02:04,690 --> 00:02:11,890 So here I've just got both in the script and what we're going to do is run a get this is a variable 28 00:02:11,890 --> 00:02:13,510 that stores that information. 29 00:02:14,020 --> 00:02:18,370 So we're doing requests don't get this is a method of requests. 30 00:02:18,730 --> 00:02:25,630 We are going to use this URL, specify our username and password which was specified over here. 31 00:02:26,350 --> 00:02:33,280 Headers that we're using are these headers and we are not going to verify our certificates. 32 00:02:35,230 --> 00:02:41,200 So I'll copy that and paste that in to the Ubuntu server. 33 00:02:41,710 --> 00:02:44,370 So here is our entire script. 34 00:02:44,380 --> 00:02:45,270 Very simple. 35 00:02:45,280 --> 00:02:55,180 Only a few lines and then I'll save that script and I'm going to run Python 3xpy and hopefully we'll 36 00:02:55,180 --> 00:03:01,120 see the interfaces on the router and there you go, all the interfaces on the router. 37 00:03:02,810 --> 00:03:04,310 There's Harvey once again. 38 00:03:06,300 --> 00:03:09,030 Who configured gigabit two on the router. 39 00:03:09,390 --> 00:03:09,660 Okay. 40 00:03:09,660 --> 00:03:17,580 But just to prove the point, let's go to Postman and let's create interface loopback. 41 00:03:17,580 --> 00:03:23,280 One, two, three, four and click send and go back to the Python script and run it again. 42 00:03:23,520 --> 00:03:25,800 Notice we've created loopback. 43 00:03:25,800 --> 00:03:26,790 One, two, three, four. 44 00:03:27,900 --> 00:03:29,550 Let's create loopback. 45 00:03:29,550 --> 00:03:31,290 One, two, three, five. 46 00:03:33,020 --> 00:03:34,760 That tells me it's created. 47 00:03:35,710 --> 00:03:37,240 Run my script again. 48 00:03:37,990 --> 00:03:38,920 There it is. 49 00:03:39,980 --> 00:03:42,620 And just for fun, let's duplicate this. 50 00:03:43,130 --> 00:03:53,420 And what we'll do is in the body say, let's create a loopback of 2000 and let's say I can see this 51 00:03:53,420 --> 00:03:55,100 using Python. 52 00:03:57,580 --> 00:03:59,380 And let's make this. 53 00:03:59,380 --> 00:04:01,870 2.2.2.2. 54 00:04:03,040 --> 00:04:03,850 Click Send. 55 00:04:04,690 --> 00:04:10,840 It's now been created back in a ubuntu python 3xpy. 56 00:04:11,590 --> 00:04:12,430 There you go. 57 00:04:13,490 --> 00:04:13,740 Okay. 58 00:04:13,760 --> 00:04:20,600 So I've shown you how to get a list of interfaces using a rest API and postman. 59 00:04:21,230 --> 00:04:23,690 Then I showed you how to do that using a python script. 60 00:04:23,810 --> 00:04:26,460 I showed you how to create interfaces using Postman. 61 00:04:26,480 --> 00:04:28,940 I showed you how to delete interfaces using Postman. 62 00:04:29,630 --> 00:04:31,310 Postman is a great way to get started. 63 00:04:31,310 --> 00:04:36,260 If you're not sure about the coding, then use the graphical user interface to get started. 64 00:04:36,290 --> 00:04:44,270 I've once again given you all the steps in this PowerPoint presentation, so download the PowerPoint 65 00:04:44,270 --> 00:04:47,780 presentation and just follow the steps and you should be able to do this yourself. 66 00:04:48,580 --> 00:04:48,780 Okay. 67 00:04:48,880 --> 00:04:49,980 Hopefully you've learned something. 68 00:04:49,990 --> 00:04:52,900 Hopefully you're now more comfortable using a rest API.