cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
455
Views
5
Helpful
2
Replies

Assistance with RESTCONF API Call

JamesMathis
Level 1
Level 1

Hello,

Can someone tell me how to add an IP Subnet to a network-object using RESTCONF?  I have no issues with adding an IP, but I get a 400 error when trying to add a subnet.

I am using an HTTP client to make this call.  The parameters as as follows:

URL:
https://X.X.X.X/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/host
HTTP Method:
PATCH

Headers: Content-Type - application/yang-data+json
Authorization Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Body:
{"Cisco-IOS-XE-object-group:host":[{"ipv4-host":"1.2.3.0 255.255.255.0"}]}

This is the error message I receive.

{"errors":{"error":[{"error-message":"missing element: ipv4-host in /ios:native/ios:object-group/ios-og:network[ios-og:name='blacklist_sources']/ios-og:obj-Mode-config-network-group/ios-og:host","error-path":"/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/host","error-tag":"malformed-message","error-type":"application"}]}}

 

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

Try this.

curl -k -v -X PATCH -u dafrey:xxxxxxx -H 'Content-Type: application/yang-data+json' \
https://192.168.0.20/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/network_address \
--data '{"network_address": [{"ipv4_addr": "10.2.1.0", "ipv4_mask": "255.255.255.0" }]}'

View solution in original post

2 Replies 2

Dan Frey
Cisco Employee
Cisco Employee

Try this.

curl -k -v -X PATCH -u dafrey:xxxxxxx -H 'Content-Type: application/yang-data+json' \
https://192.168.0.20/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/network_address \
--data '{"network_address": [{"ipv4_addr": "10.2.1.0", "ipv4_mask": "255.255.255.0" }]}'

Andrea Testino
Cisco Employee
Cisco Employee

James,

Based on the below YANG model, you may want to try network_address since you're adding a subnet as opposed to ipv4-host. Request below:

 

curl -X 'PATCH' \
  'https://<IP_ADDRESS>:443/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=,/obj-Mode-config-network-group/network_address' \
  -H 'accept: application/yang-data+json' \
  -H 'Content-Type: application/yang-data+json' \
  -d '{
  "network_address": [
    {
      "ipv4_addr": "1.2.3.0",
      "ipv4_mask": "255.255.255.0"
    }
  ]
}'

 

 YANG model:

 

```
(yang-test-venv) atestini@ATESTINI-M-R61B 1791 % pyang -f tree Cisco-IOS-XE-object-group.yang 
module: Cisco-IOS-XE-object-group

  augment /ios:native/ios:object-group:
    +--rw network* [name]
    |  +--rw name                             string
    |  +--rw obj-Mode-config-network-group
    |     +--rw network_address* [ipv4_addr ipv4_mask]
    |     |  +--rw ipv4_addr    inet:ipv4-address
    |     |  +--rw ipv4_mask    inet:ipv4-address
    |     +--rw description?       string
    |     +--rw group-objects* [network-group]
    |     |  +--rw network-group    -> /ios:native/object-group/ios-og:network/name
    |     x--rw group-object?      string
    |     +--rw host* [ipv4-host]
    |     |  +--rw ipv4-host    inet:host
    |     +--rw addr-ranges* [addr-range-start addr-range-end]
    |     |  +--rw addr-range-start    inet:ipv4-address
    |     |  +--rw addr-range-end      inet:ipv4-address
    |     x--rw range
    |        x--rw ip-addr-min?   inet:ipv4-address
    |        x--rw ip-addr-max?   inet:ipv4-address
    <snip>
```

 

Hope that helps!

 

- Andrea, CCIE #56739 R&S