VMware Networking Community
Saurabhb309
Contributor
Contributor

NSX-T Declarative API

I need to use declarative API to perform some automation tasks, for this instance i need to create few segments.

Below code is to create just a single segment and i am putting a Patch request to https://nsx-fqdn/policy/api/v1/infra

{

    “resource_type”: “infra”,

    “children”: [

        {

        “resource_type”: “ChildSegment”,

        “Segment”: {

            “resource_type”: “Segment”,

            “display_name”: “Post01”,

            “id”: “Post01”

                   }

        }     

                ]

}

But i get the below error, can anyone please help to get this right
{

    "httpStatus": "BAD_REQUEST",

    "error_code": 220,

    "module_name": "common-services",

    "error_message": "Unexpected character ('“' (code 8220 / 0x201c)): was expecting double-quote to start field name"

}

Tags (1)
0 Kudos
2 Replies
chrisgnoon
Enthusiast
Enthusiast

https://code.vmware.com/apis/1030/nsx-t

Section: Create or update a segment

 

PATCH https://<policy-mgr>/policy/api/v1/infra/segments/web-tier>?force=true

{

    "display_name":"web-tier",

    "subnets": [

        {

            "gateway_address": "40.1.1.1/16",

            "dhcp_ranges": [ "40.1.2.0/24" ]

         }

    ] 

}

Chris Noon | CCDP | CCNP | VCDX 289
Don't forget to mark as solved if your questions are answered.
0 Kudos
DaleCoghlan
VMware Employee
VMware Employee

You need a bit more information in your hierarchical API payload

As an example, the following creates 2 x VLAN backed segments

{
  "resource_type": "Infra",
  "children": [
    {
      "resource_type": "ChildSegment",
      "marked_for_delete": "false",
      "Segment": {
        "description": "10.10.10.64/27",
        "vlan_ids": [
          1234
        ],
        "display_name": "v1234_Saurabhb309_nsx_prod",
        "type": "DISCONNECTED",
        "id": "v1234_Saurabhb309_nsx_prod",
        "transport_zone_path": "/infra/sites/default/enforcement-points/default/transport-zones/a95c914d-748d-497c-94ab-10d4647daeba",
        "resource_type": "Segment",
        "tags": [
          {
            "scope": "migration/cluster",
            "tag": "PROD"
          }
        ],
        "replication_mode": "MTEP"
      }
    },
    {
      "resource_type": "ChildSegment",
      "marked_for_delete": "false",
      "Segment": {
        "description": "10.10.11.0/22",
        "vlan_ids": [
          1235
        ],
        "display_name": "v1235_Saurabhb309_nsx_dev",
        "type": "DISCONNECTED",
        "id": "v1235_Saurabhb309_nsx_dev",
        "transport_zone_path": "/infra/sites/default/enforcement-points/default/transport-zones/a95c914d-748d-497c-94ab-10d4647daeba",
        "resource_type": "Segment",
        "tags": [
          {
            "scope": "migration/cluster",
            "tag": "NON-PROD"
          }
        ],
        "replication_mode": "MTEP"
      }
    }
  ]
}

 

Dale

0 Kudos