Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Submitting a GET Request to the REST API

 

For an rpc command, the general format of the endpoints is:

scheme://device-name:port/rpc/method[@attributes]/params

  • scheme: http or https

  • method: The name of any Junos OS rpc command. The method name is identical to the tag element. For more information, see the Junos XML API Operational Developer Reference.

  • params: Optional parameter values (name[=value]).

To authenticate your request, submit the base64-encoded username and password included in the Authorization header:

curl -u "username:password" http://device-name:port/rpc/get-interface-information

To specify rpc data as a query string in the URI for GET requests, you can use a ? following the URI with the & delimiter separating multiple arguments, or use the / delimiter, as shown in these equivalent cURL calls:

For example:

curl -u "username:password" http://device-name:port/rpc/get-interface-information?interface-name=cbp0&snmp-index=1
curl -u "username:password" http://device-name:port/rpc/get-interface-information/interface-name=cbp0/snmp-index=1

HTTP Accept headers can be used to specify the return format using one of the following Content-Type values:

  • application/xml (the default)

  • application/json

  • text/plain

  • text/html

For example, the following cURL call specifies an output format of JSON:

You can also specify the output format using the optional format parameter.

For example, the <get-software-information> tag element retrieves software process revision levels. The following HTTPS GET request executes this command and retrieves the results in JSON format:

https://device-name:3000/rpc/get-software-information@format=json

The following Python program uses the REST interface to execute the get-route-engine-information RPC, extracts the data from the response, and plots a graph of the CPU load average: