Loop in data file

Hello

I tried to find a solution in other topics but had no luck. I have to raise an API call into NSX-T to create a group.

Body of API call :

{
    "expression": [
        {
            "ip_addresses": [
                "{{members}}"
            ],
            "resource_type": "IPAddressExpression"
        }
    ],
    "resource_type": "Group",
    "display_name": "Test",
    "description": "{{group_name}}",
    "_system_owned": false,
    "_protection": "NOT_PROTECTED",
    "_revision": 0
}

I want to use csv file with the below structure

group_name,members
Test,1.1.1.1

And this is fine, but what to do if I have more members and the number of them is different in each row? CSV file for example:

group_name,members
Test,1.1.1.1, 2.2.2.2, 3.3.3.3
Test2,2.2.2.2, 3.3.3.3

Hey @bobocjusz ,

This isn’t valid csv as the other members wouldn’t belong to any column. You’d need to either:

  • have different member columns and leave them empty when there is only a few members, e.g.:
group_name,member1,member2, member3
Test,1.1.1.1, 2.2.2.2, 3.3.3.3
Test2,2.2.2.2, 3.3.3.3,,
Test3,1.1.1.1,,,
  • use JSON instead of CSV so you can store more complex type of items like an array of members:
[
 {
   "group_name": "Test",
   "members": ["1.1.1.1"," 2.2.2.2"," 3.3.3.3"]
 },
 {
   "group_name": "Test2",
   "members": ["2.2.2.2", "3.3.3.3"]
 }
]

Thank you Arlemi for you support :slight_smile:

1 Like