NDFC
Postman Collection

Test NDFC REST API using Postman

In this section, we will use the Collection imported to modify interface Ethernet1/1 on both leaf switches of fabric fabric-stage and create one VRF and one Network in the same fabric.

For the sake of time, requests in this section of the lab use pre-set collection variables. These will be used in the API endpoint URLs and/or in the API endpoint body (payload). For reference, you can find the preset values in the screenshot below:

Step 1 - Acquire the JWT Token

  1. Click request Login on the left side
  2. Review the Body
  3. Click the Send

Example of Response:

    {
        "jwttoken": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijdjc3ZqYjltZDBzcTl6ODI4c2o1Nm9rcHZ3eWpuOGp3IiwidHlwIjoiSldUIn0.eyJhdnBhaXIiOiJzaGVsbDpkb21haW5zPWFsbC9hZG1pbi8iLCJjbHVzdGVyIjoiNGU0NDJkMzEtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwIiwiZXhwIjoxNjg1NDAwNzY1LCJpYXQiOjE2ODUzOTk1NjUsImlkIjoiNDhkMTA1YmRmYmM0OWE1ZmNmMzlhMTBiOTYxMzg2ZTYxZGZlNDAwODVjYjAzMTVkODE4Yjc2MWM1NzM1ZGFmYSIsImlzcyI6Im5kIiwiaXNzLWhvc3QiOiIxMC4xNS4wLjExIiwicmJhYyI6W3siZG9tYWluIjoiYWxsIiwicm9sZXNSIjoxNjc3NzIxNiwicm9sZXNXIjoxLCJyb2xlcyI6W1siYWRtaW4iLCJXcml0ZVByaXYiXSxbImFwcC11c2VyIiwiUmVhZFByaXYiXV19XSwic2Vzc2lvbmlkIjoiZVV4Q1ZSRldZMHdGZTZWNVJFaU5sWkw3IiwidXNlcmZsYWdzIjowLCJ1c2VyaWQiOjI1MDAyLCJ1c2VybmFtZSI6ImFkbWluIiwidXNlcnR5cGUiOiJsb2NhbCJ9.VqBXcix8hLOjO79UhFCEkQb2rcoEA5LhcT32DpIwER8gxWoeggDj19v3elfG_BL1GiAMxfaBmtDTR1v7K1QGaaxRccFDGxJzoiDJGKMbpDQj-IrUsX7Y0_zq-fp2tTQSKshD39VnW-iwLvsvAyzZP9kbqbO9qkFkQVOfUISq6tNulwDpUkXTfh81sVl0E1n6kzdKj9q9kcGwX_3VHXSLdewzl9a22i3VT-YkYvZvSFG4ze8TYqxDtfkAd-Cs8z3hnIkpPxd_X7-kABEE_hBJ81CJh5VIlEdqht2R3xcqyAC9R3nWYrD02IcP27Y8Z4jCSfQN14XAGhZud5MLCOSrpQ",
        "username": "admin",
        "usertype": "local",
        "rbac": "[{\"domain\":\"all\",\"rolesR\":16777216,\"rolesW\":1,\"roles\":[[\"admin\",\"WritePriv\"],[\"app-user\",\"ReadPriv\"]]}]",
        "statusCode": 200,
        "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijdjc3ZqYjltZDBzcTl6ODI4c2o1Nm9rcHZ3eWpuOGp3IiwidHlwIjoiSldUIn0.eyJhdnBhaXIiOiJzaGVsbDpkb21haW5zPWFsbC9hZG1pbi8iLCJjbHVzdGVyIjoiNGU0NDJkMzEtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwIiwiZXhwIjoxNjg1NDAwNzY1LCJpYXQiOjE2ODUzOTk1NjUsImlkIjoiNDhkMTA1YmRmYmM0OWE1ZmNmMzlhMTBiOTYxMzg2ZTYxZGZlNDAwODVjYjAzMTVkODE4Yjc2MWM1NzM1ZGFmYSIsImlzcyI6Im5kIiwiaXNzLWhvc3QiOiIxMC4xNS4wLjExIiwicmJhYyI6W3siZG9tYWluIjoiYWxsIiwicm9sZXNSIjoxNjc3NzIxNiwicm9sZXNXIjoxLCJyb2xlcyI6W1siYWRtaW4iLCJXcml0ZVByaXYiXSxbImFwcC11c2VyIiwiUmVhZFByaXYiXV19XSwic2Vzc2lvbmlkIjoiZVV4Q1ZSRldZMHdGZTZWNVJFaU5sWkw3IiwidXNlcmZsYWdzIjowLCJ1c2VyaWQiOjI1MDAyLCJ1c2VybmFtZSI6ImFkbWluIiwidXNlcnR5cGUiOiJsb2NhbCJ9.VqBXcix8hLOjO79UhFCEkQb2rcoEA5LhcT32DpIwER8gxWoeggDj19v3elfG_BL1GiAMxfaBmtDTR1v7K1QGaaxRccFDGxJzoiDJGKMbpDQj-IrUsX7Y0_zq-fp2tTQSKshD39VnW-iwLvsvAyzZP9kbqbO9qkFkQVOfUISq6tNulwDpUkXTfh81sVl0E1n6kzdKj9q9kcGwX_3VHXSLdewzl9a22i3VT-YkYvZvSFG4ze8TYqxDtfkAd-Cs8z3hnIkpPxd_X7-kABEE_hBJ81CJh5VIlEdqht2R3xcqyAC9R3nWYrD02IcP27Y8Z4jCSfQN14XAGhZud5MLCOSrpQ"
    }

Postman will use the cookie received from Nexus Dasboard automatically for any subsequent requests in the same collection:

Note

As mentioned in previous sections, the token is valid for 20 minutes by default. If any of the following steps fail with 401 Unauthorized error, just re-send the Login request again to acquire a new token.

Step 2 - Query the Fabric Inventory

The majority of the APIs that are related to switches will use the Serial Number as the key to identify the switch you would like to operate on since the Serial Number is unique. The application you created usually will ask for user input and the Serial Number is not easy to use. Usually, the application should use fabric name + hostname/ip address to programmatically identify the switch and find the correct serial number for subsequence requests. For example, in the Ansible NDFC collection, the user will use the IP address of the switch in the playbook instead of the Serial Number. To get the inventory detail of a given fabric:

  1. Click request Query Fabric Inventory on the left side
  2. Click the Send




  3. Click the Scripts to review the post-request script. Essentially, it will find the correct Serial Number for each leaf switches and update the collection variables for future usage.




  4.     const jsonData = JSON.parse(responseBody);
        const leaf1 = "staging-leaf1"
        const leaf2 = "staging-leaf2"
    
        for (var i = 0; i < jsonData.length; i ++) {
            if (leaf1 === jsonData[i].logicalName) {
                pm.collectionVariables.set("sn_leaf1", jsonData[i].serialNumber);
            }
            if (leaf2 === jsonData[i].logicalName) {
                pm.collectionVariables.set("sn_leaf2", jsonData[i].serialNumber);
            }
        }
    
Your NDFC REST API collection variables for sn_leaf1 and sn_leaf2 variables now look something like the below screenshot:

Note

The remaining steps in this section will make modifications using Postman to your NDFC fabric called fabric-stage
You will verify these changes in the next section of the lab.

Step 3 - Modify Interfaces

  1. Click request Change Interface to Access on the left side
  2. Review the Body
  3. Click the Send

Step 4 - Deploy the Inteface Configuration

  1. Click request Deploy Interface Configuration on the left side
  2. Review the Body
  3. Click the Send

Step 5 - Create VRF PostmanVRF

  1. Click request Create VRF on the left side
  2. Review the Body
  3. Click the Send

Step 6 - Attach VRF PostmanVRF to Leaf Switches

If you have gone through the basic GUI workflow of NDFC, you might have noticed that we didn't attach the VRF to switches manually, it is attached along with the Network automatically. However, when we automate the NDFC configuration, it will be a good idea to make sure the result is deterministic. So we would suggest making sure the VRF is attached to the switches by calling the attachment API.

  1. Click request Attach VRF to Switch on the left side
  2. Review the Body
  3. Click the Send

Step 7 - Deploy VRF PostmanVRF Configuration

  1. Click request Deploy VRF on the left side
  2. Review the Body
  3. Click the Send

Step 8 - Create Network PostmanNet1

  1. Click request Create Network on the left side
  2. Review the Body
  3. Click the Send

Step 9 - Attach Network PostmanNet1 to Leaf Switches and Interfaces

  1. Click request Attach Network to Switch and Interface on the left side
  2. Review the Body
  3. Click the Send

Step 10 - Deploy Network PostmanNet1 Configuration

  1. Click request Deploy Network on the left side
  2. Click the Send


Continue to the next section to verify what you have created with Postman requests in NDFC.