BLOGPOST#149 Network Automation using Cisco API: A Step-by-Step Guide to Using Postman and Python for HTTP Delete Method

Introduction:

Deleting specific elements from an API can be an essential task for many developers. In this tutorial, we’ll be exploring how to use Postman and Python for the HTTP Delete method. Let’s dive in!

Step 1: Select the Delete Method in Postman:
To perform a delete method using Postman, we first need to select the delete method. In Postman, click on the drop-down list of methods and select the delete method.

Step 2: Provide URL and Payload:
To delete a particular interface using Postman, we need to provide the URL of the interface we want to delete. In the payload, we don’t need to pass any data. Let’s say we want to delete loopback 103. We’ll paste the URL and then perform the delete method. Once the delete method is executed, the specified interface will be deleted.

Step 3: Run the Request:
Click on the send button to execute the request. This will delete the particular interface, and you’ll receive a response code to confirm the deletion.

Step 4: Verify Device Configuration:
It’s always good practice to verify the device configuration to ensure that the deletion was successful. You can check that loopback 103 is no longer present.

Step 5: Delete Elements from Python Code:
In Python, the delete method is called in the same way as in Postman, but you need to provide the URL and payload differently. Here’s an example of how to delete an interface in Python:

import json
import requests
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

url = "https://192.168.0.63/restconf/data/Cisco-IOS-XE-native:native/interface/Loopback=1002"


headers = {
    'Accept': 'application/yang-data+json',
    'Content-Type': 'application/yang-data+json',
    'Authorization': 'Basic YWRtaW46YWRtaW4='
}

response = requests.request("DELETE", url, headers=headers, verify=False)

print(response.text)
print(response.status_code)
print(response.reason)

In this example, we’re using the requests library to send a delete request to the URL that corresponds to loopback 102. We then print the response code to confirm that the deletion was successful.

That’s it! You now know how to use Postman and Python for the step delete method. Remember to always verify your changes and ensure that your API is functioning as intended. Happy coding!

Conclusion:
In this tutorial, we have seen how to delete elements from Postman and Python using the DELETE method. Deleting an element is a crucial operation when working with APIs, and it is essential to know how to perform it. We hope this tutorial has been helpful in showing you how to delete a particular interface using Postman and Python. If you have any questions or feedback, feel free to leave a comment below.

Complete Script for Reference:

import json
import requests
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

url = "https://192.168.0.63/restconf/data/Cisco-IOS-XE-native:native/interface/Loopback=1002"


headers = {
    'Accept': 'application/yang-data+json',
    'Content-Type': 'application/yang-data+json',
    'Authorization': 'Basic YWRtaW46YWRtaW4='
}

response = requests.request("DELETE", url, headers=headers, verify=False)

print(response.text)
print(response.status_code)
print(response.reason)

Unlock the Power of Network Automation ! Enroll in our Comprehensive Udemy Course Today !

Topics & libraries Covered:

  • PARAMIKO, NETMIKO, NAPALM, NORNIR and NCCLIENT libraries
  • Cisco IOS, vIOS and NXOS SSH Automation
  • Cisco CSR 1000v Netconf and RestAPI examples
  • NX-API Automation (NXAPI CLI and bash)
  • PyATS, Cisco Genie Parser
  • NETCONF & RESTCONF API Automation
  • YANG Data Models and YANG Suite demo
  • IPAddress Module and requests module
  • Python Core Fundamentals for Network Engineers
  • Python Data Types
  • Python Text & CSV File operations (read/write) device data
  • Python IDE (PyCharm) Setup for Network Automation
  • GNS3 Lab Setup for Network Automation
  • Python Functions, Modules, Classes and Objects Tutorial
  • Python Multithreading Examples (threading and concurrent futures)
  • Python Logging, schedule and Email for monitoring
  • Python SSH CLI Parsing Using RegEx
  • How to Use JSON, YAML and XML Files for Device Config