cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2626
Views
0
Helpful
6
Replies

Can't do PUT/POST by REST API on CSR1000v

nklo_2010
Level 1
Level 1

Hi Cisco, and all,

I'm trying to do REST API on CSR1000V (by setting up the OVF VM which is of ios xe  3.11s).

Succeeded in GET, but everytime doing PUT, it says like below, that there is unsupported content which I sent thru' JSON:


C:\Users\curl>curl https://192.168.241.26/api/v1/global/
host-name -H "x-auth-token: DHLjE+f3MaC85SozPTodycDFZZHxsu9otg1pV2cZjF8=" -H "Accept:application/json" -v -k

* Trying 192.168.241.26...
* TCP_NODELAY set
* Connected to 192.168.241.26 (192.168.241.26) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.0 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server key exchange (12):
* TLSv1.0 (IN), TLS handshake, Server finished (14):
* TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.0 (OUT), TLS change cipher, Client hello (1):
* TLSv1.0 (OUT), TLS handshake, Finished (20):
* TLSv1.0 (IN), TLS change cipher, Client hello (1):
* TLSv1.0 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.0 / DHE-RSA-AES256-SHA
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=US; O=Cisco; ST=California; CN=restful_api
* start date: May 26 05:32:46 2013 GMT
* expire date: May 24 05:32:46 2023 GMT
* issuer: C=US; O=Cisco; ST=California; CN=restful_api
* SSL certificate verify result: self signed certificate (18), continuing anywa
y.
> GET /api/v1/global/host-name HTTP/1.1
> Host: 192.168.241.26
> User-Agent: curl/7.50.3
> x-auth-token: DHLjE+f3MaC85SozPTodycDFZZHxsu9otg1pV2cZjF8=
> Accept:application/json
>
< HTTP/1.1 200 OK
< Server: nginx/1.4.2
< Date: Tue, 11 Oct 2016 02:44:15 GMT
< Content-Type: application/json
< Content-Length: 53
< Connection: keep-alive
<
{"kind": "object#host-name", "host-name": "csr1kv-1"}* Curl_http_done: called pr
emature == 0
* Connection #0 to host 192.168.241.26 left intact


C:\Users\curl>curl -X PUT https://192.168.241.26/api/v1/
global/host-name -H "x-auth-token: DHLjE+f3MaC85SozPTodycDFZZHxsu9otg1pV2cZjF8="
-H "Accept:application/json" -v -k -H "content-type:application/json" -d '{"host-name":"csr1000v1"}'

* Trying 192.168.241.26...
* TCP_NODELAY set
* Connected to 192.168.241.26 (192.168.241.26) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.0 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server key exchange (12):
* TLSv1.0 (IN), TLS handshake, Server finished (14):
* TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.0 (OUT), TLS change cipher, Client hello (1):
* TLSv1.0 (OUT), TLS handshake, Finished (20):
* TLSv1.0 (IN), TLS change cipher, Client hello (1):
* TLSv1.0 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.0 / DHE-RSA-AES256-SHA
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=US; O=Cisco; ST=California; CN=restful_api
* start date: May 26 05:32:46 2013 GMT
* expire date: May 24 05:32:46 2023 GMT
* issuer: C=US; O=Cisco; ST=California; CN=restful_api
* SSL certificate verify result: self signed certificate (18), continuing anywa
y.
> PUT /api/v1/global/host-name HTTP/1.1
> Host: 192.168.241.26
> User-Agent: curl/7.50.3
> x-auth-token: DHLjE+f3MaC85SozPTodycDFZZHxsu9otg1pV2cZjF8=
> Accept:application/json
> content-type:application/json
> Content-Length: 23
>
* upload completely sent off: 23 out of 23 bytes
< HTTP/1.1 400 BAD REQUEST
< Server: nginx/1.4.2
< Date: Tue, 11 Oct 2016 02:45:57 GMT
< Content-Type: application/json
< Content-Length: 147
< Connection: keep-alive
<
{"error-code": 400, "error-message": "HTTP Bad Request", "detail": "JSON body in
the request is either malformed or contains unsupported encoding"}* Curl_http_d
one: called premature == 0
* Connection #0 to host 192.168.241.26 left intact


I followed the instructions at http://www.cisco.com/c/en/us/td/docs/routers/csr1000/software/restapi/restapi.html, and tried some other PUT, eg. domain-name, but got the same error msg.
When trying POST operation, got same error msg too.


So I'm wondering if I miss something (e.g.some other key:value pairs or patterns which are needed to input)  at JSON body...
Appreciate if any kind advice to me to solve this.


Thanks.

6 Replies 6

Geevarghese Cheria
Cisco Employee
Cisco Employee

Hi,

   Did you had any chance to check with the step by step procedure mentioned in the learning lab (RESTCONF) and replicate the same in your lab..

Cisco DevNet Learning Labs

Thanks and Regards,

Geevarghese

yawming
Cisco Employee
Cisco Employee

I was  told REST API(for ios xe ?) will be obsoleted, and to focus on RESTCONF, not REST :-)

I can't even get past authentication. Getting a 411 length required error, even though I'm passing Content-Length: 0. This is Cisco IOS XE Software, Version 16.06.04.

 

➜ ~ curl -v -X POST https://192.168.10.22/api/v1/auth/token-services -H "Accept:application/json" -u "cisco:cisco" -k -1 -d ""
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 192.168.10.22...
* TCP_NODELAY set
* Connected to 192.168.10.22 (192.168.10.22) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /usr/local/etc/openssl/cert.pem
CApath: /usr/local/etc/openssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* NPN, negotiated HTTP1.1
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Next protocol (67):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=IOS-Self-Signed-Certificate-3735911966
* start date: Aug 30 16:13:10 2018 GMT
* expire date: Jan 1 00:00:00 2020 GMT
* issuer: CN=IOS-Self-Signed-Certificate-3735911966
* SSL certificate verify result: self signed certificate (18), continuing anyway.
* Server auth using Basic with user 'cisco'
> POST /api/v1/auth/token-services HTTP/1.1
> Host: 192.168.10.22
> Authorization: Basic Y2lzY286Y2lzY28=
> User-Agent: curl/7.61.0
> Accept:application/json
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 411 Length Required
< Server: nginx
< Date: Fri, 31 Aug 2018 16:28:20 GMT
< Transfer-Encoding: chunked
< Connection: close
< Accept-Ranges: none
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=7884000
<
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
➜ ~

Check the TCP connection port, it should be 55443 by default.

This can be changed with the command restful-api local-port xxxx inside remote-management mode.

HTH

a-gould
Level 1
Level 1

I can't make Postman do a PUT into a DevNet CSR1000v.  I can do GET's all day, and get good responses.  But not PUT's.  I'm just trying to do a simple interface description change.

 

I continue to get responses like this... end of file... malformed messages.

 

Any idea why this is happening?

 

<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">

    <error>

        <error-message>End-of-file reached in XML stream</error-message>

        <error-path>/ietf-interfaces:interfaces</error-path>

        <error-tag>malformed-message</error-tag>

        <error-type>application</error-type>

    </error>

</errors>

a-gould
Level 1
Level 1

I figured out my problem.  The feedback received within RESTCONF, XML, and HTTP status codes are helpful in narrowing down the possible issues.  This cURL works to perform a IOS-XE CSR1000v hostname change (done on the terminal of a linux/ubuntu host)

 

curl -k --location --request PATCH 'https://ios-xe-mgmt.cisco.com:9443/restconf/data/Cisco-IOS-XE-native:native/hostname' --header 'Accept: application/yang-data+xml' --header 'Authorization: Basic (intentionally removed)' --header 'Content-Type: application/yang-data+xml' --data-raw ' <hostname xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"  xmlns:ios="http://cisco.com/ns/yang/Cisco-IOS-XE-native">csr1kv</hostname>'