VMware Cloud Community
globalhawk
Contributor
Contributor

Unable to add new App Firewall Rule using REST API call to vCNS 5.1

I am trying to add some new App Firewall rules to vCNS 5.1

These are the following code. But I keep getting this error message "The remote server returned an error: (412) Precondition Failed.". Any help ?

TestRule2 is the new rule that i am trying to add.

Request Header has generationNumber added as If-Match

Request Body

POST https://vcns-ip/api/2.0/app/firewall/mycontextid/config

<?xml version="1.0" encoding="UTF-8"?>

<VshieldAppConfiguration>

  <firewallConfiguration contextId="datacenter-2" generationNumber="1394666438168" provisioned="true">

    <layer3FirewallRule id="0" precedence="none" disabled="false">

      <name>TestRule2</name>

      <action>allow</action>

      <logged>false</logged>

      <notes /><source>

      <address exclude="false" />

      <portInfo />

      </source>

    </layer3FirewallRule>

    <layer3FirewallRule id="1002" precedence="default" disabled="false">

      <name>Default Rule</name>

      <action>allow</action>

      <logged>false</logged>

      <notes />

    </layer3FirewallRule>

    <layer2FirewallRule id="1001" precedence="default" disabled="false">

      <name>Default Rule</name>

      <action>allow</action>

      <logged>false</logged>

      <notes />

    </layer2FirewallRule>

  </firewallConfiguration>

</VshieldAppConfiguration>

Tags (4)
0 Kudos
2 Replies
Pina
Contributor
Contributor

I had a similar problem and managed to solve by changing the header:

If-Match : 1411063473041

by

If-Match : "1411063473041"

I use a REST Client in Firefox.

0 Kudos
Czernobog
Expert
Expert

For anyone who, like me, started having the 412 errors in NSX 6.4.5 when using PUT requests - in this version the quotes have to be removed from the header parameter, or else, if you pull the etag number and pass it on without editing, your REST call will fail.

Good:

If-Match: "1559824065743"

Status code: 200

Bad:

If-Match: ""1559824065743""

Status code: 412

0 Kudos