Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



Junos® OS REST API Guide

...


For an rpc command, the general format of the endpoints is:
scheme://device-name:port/rpc/method[@attributes]/params


default ports:

http:   3000

https:   3443


Code Block
titlerest config
vagrant@vqfx-re> show configuration system services
. . .
rest {
    http {
        port 8080;
    }
    enable-explorer;
}


vagrant@vqfx-re> show configuration system services | display set
set system services ssh root-login allow
set system services netconf ssh
set system services rest http port 8080
set system services rest enable-explorer


work out the rpc command


Code Block
titlerpc call
root> show interfaces | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/19.3R0/junos">
    <rpc>
        <get-interface-information>
        </get-interface-information>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

root>


root> show interfaces ge-0/0/0.0 | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/19.3R0/junos">
    <rpc>
        <get-interface-information>
                <interface-name>ge-0/0/0.0</interface-name>
        </get-interface-information>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

root> show interfaces ge-0/0/0.0 terse | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/19.3R0/junos">
    <rpc>
        <get-interface-information>
                <terse/>
                <interface-name>ge-0/0/0.0</interface-name>
        </get-interface-information>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>


show interfaces

/rpc/get-interface-information

/rpc/get-interface-information?terse

show interfaces ge-0/0/0.0

/rpc/get-interface-information?interface-name=ge-0/0/1

/rpc/get-interface-information?terse&interface-name=ge-0/0/1

show interfaces ge-0/0/0.0 terse /rpc/get-interface-information


With Postman

Config using RPC call

show configuration system host-name | display xml


Code Block
titleshow config
juniper@SDK-vSRX_JCL_EWF> show configuration system host-name | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.1R0/junos">
    <configuration junos:commit-seconds="1605466556" junos:commit-localtime="2020-11-15 18:55:56 UTC" junos:commit-user="juniper">
            <system>
                <host-name>SDK-vSRX_JCL_EWF</host-name>
            </system>
    </configuration>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

Extract the configuration part:

<configuration ><system>
<host-name>SDK-vSRX_JCL_EWF</host-name>
</system></configuration>


curl config


Code Block
titlecurl POST
curl -u "username:password" http://device-name:port/rpc?stop-on-error=1 
-d "<lock-configuration/>
  <load-configuration>
    <configuration><system><host-name>foo</host-name></system></configuration>
  </load-configuration>
  <commit/>
   <unlock-configuration/>" 


REST-API explorer

check the cURL commands

Check the response

Image Added