When there is a requirement for creating multiple context profiles with PUT API calls in the NSX Manager, administrators may face difficulties in correctly formatting the request payload or using the appropriate attribute keys. This article explains how to construct the correct JSON payload and execute the PUT request successfully using the NSX Policy API.
VMware NSX
Improper formatting of the JSON payload or incorrect usage of attribute keys (e.g., APP_ID, DOMAIN_NAME, CUSTOM_URL) can lead to API errors or incorrect context profile creation.
To create a context profile that includes multiple attribute types, such as applications (APP_ID) and domain names (DOMAIN_NAME), use the following PUT API request to the NSX Manager.
PUT https://<NSX-Manager-IP>/policy/api/v1/infra/context-profiles/{context-profile-id}
(Replace <NSX-Manager-IP> with your NSX Manager's IP address or FQDN, and {context-profile-id} with a unique identifier for your context profile.)
Use the following JSON body in the PUT request:
{ "resource_type": "PolicyContextProfile", "id": "context-profile-id", "display_name": "write the name which you want to display in the NSX context profile list", "attributes": [ { "key": "APP_ID", "value": ["application name 1", "Application name 2"], "datatype": "STRING", "attribute_source": "SYSTEM" }, { "key": "DOMAIN_NAME", "value": ["example.com", "sub.example.com"], "datatype": "STRING", "attribute_source": "SYSTEM" } ]}
To see the list of valid application names, domain-related keys, and other supported values:
GET https://<NSX-Manager-IP>/policy/api/v1/infra/context-profiles/attributes
To verify that the profile was created:
GET https://<NSX-Manager-IP>/policy/api/v1/infra/context-profiles
Or for a specific context profile:
GET https://<NSX-Manager-IP>/policy/api/v1/infra/context-profiles/{context-profile-id}