Examples using object body requests

The following sections demonstrate how to interact with WAPI via a single entry point.

Single object body request example

Use a POST request to get the Host record with the name “test.somewhere.com”:

https://1.2.3.4/wapi/v2.10.5/request

With a body:

{
    "data": {
        "name": "test.somewhere.com"
    },
    "method": "GET",
    "object": "record:host"
}

Multiple object body request example

Use a POST request to get the Host record with the name “test.somewhere.com”, save its reference to the state object and use it for an update operation:

https://1.2.3.4/wapi/v2.10.5/request

With a body:

[{
    "method": "STATE:ASSIGN",
    "data": {
            "host_name": "test.somewhere.com"
    }
},
{
    "method": "GET",
    "object": "record:host",
    "data": {
            "name": "##STATE:host_name:##"
    },
    "assign_state": {
                    "host_ref": "_ref"
    },
    "enable_substitution": true,
    "discard": true
 },
 {
    "method": "PUT",
    "object": "##STATE:host_ref:##",
    "enable_substitution": true,
    "data": {
            "comment": "new comment"
    },
    "args": {
        "_return_fields": "comment"
    },
    "assign_state": {
                    "updated_comment": "comment"
    },
    "discard": true
 },
 {
    "method": "STATE:DISPLAY"
 }
]

Returns with a body:

{
     "host_name": "test.somewhere.com",
     "host_ref": "record:host/ZG5...zdA:test.somewhere.com/default",
     "updated_comment": "new comment"
}

Extensible attribute example

Use a POST request to copy extensible attribute “Building” from an existing network to a new one using “assign_state” to save the value in the state object:

https://1.2.3.4/wapi/v2.10.5/request

With a body:

[{
    "method": "GET",
    "object": "network",
    "data": {
            "network": "10.1.0.0/16"
    },
    "args": {
            "_return_fields+": "extattrs"
        },
    "assign_state": {
        "ea_value": "*Building"
    },
    "discard": true
 },
 {
    "method": "POST",
    "object": "network",
    "data": {
            "network": "20.1.0.0/16",
            "extattrs": {
                        "Building": {
                                    "value": "##STATE:ea_value:##"
                        }
            }
    },
    "enable_substitution": true
 }
]