Solved

GET works, but POST doesn't on the API


We're trying to make the REST API work as described in the docs. Via Python 3.6 "requests" I am able to send GET messages that work, but whenever I try to use POST I receive the error...

Client error
POST method not allowed.
Documentation related to this error http://docs.cumulusnetworks.com

One of your doc examples includes a POST message so I am assuming these methods are allowed.

Example provided:
code:
 curl -X POST -k -u user:pw -H "Content-Type: application/json" -d '{"cmd": "show counters"}' https://192.168.0.32:8080/nclu/v1/rpc



Is there something special I have to do to further enable POST requests?
icon

Best answer by CurtisO 30 October 2018, 16:35

Turned out to be user error. While the URL in the curl example includes some pathing, the GET URL did not. I had not updated my origin URL in the POST request. Once I accurately matched my URL to the POST, all worked as expected.

Sample:

code:
import json
import requests
from requests.auth import HTTPBasicAuth
requests.packages.urllib3.disable_warnings()

# Make a POST call to the target Cumulus Switch
url = "https://{ip}:8080/nclu/v1/rpc".format(ip=ip_address)
payload = '{"cmd": "show interface json"}'
headers = {'Content-Type': 'application/json'}
response = requests.post(url=url,
data=payload,
headers=headers,
auth=HTTPBasicAuth(app.config['USERNAME'], app.config['PASSWORD']),
verify=False)

View original

8 replies

Userlevel 3
Thanks @CurtisO , I'm not sure why you're seeing that. I'm asking around and hopefully will get you an answer soon.

In the meantime, here's the direct link to the API docs: https://docs.cumulusnetworks.com/display/DOCS/HTTP+API
Userlevel 3
Hi @CurtisO engineering suggested you open a ticket with our support team so they can review you cl-support ticket. One thing that comes to mind is that the user might not have write privileges.
Yes, I set up HTTP API based on that document. As I said, I am successfully receiving GET method. I'm using a lab VM of the Cumulus Linux host with an admin user, but it's not actually root so maybe.
Userlevel 3
OK maybe it is a permissions thing. If you could check and let us know that would be great @CurtisO
I'm not sure what file or directory a POST request would be writing to in order to check permissions. I'm not an nginx guru. The image we are using for test is right off the cumulus website. I am using basic auth with the default 'cumulus' user credentials.
Userlevel 3
OK thanks @CurtisO ; your best bet would be to file a ticket with our support team so they can dig in and help you out.
Turned out to be user error. While the URL in the curl example includes some pathing, the GET URL did not. I had not updated my origin URL in the POST request. Once I accurately matched my URL to the POST, all worked as expected.

Sample:
code:
import json
import requests
from requests.auth import HTTPBasicAuth
requests.packages.urllib3.disable_warnings()

# Make a POST call to the target Cumulus Switch
url = "https://{ip}:8080/nclu/v1/rpc".format(ip=ip_address)
payload = '{"cmd": "show interface json"}'
headers = {'Content-Type': 'application/json'}
response = requests.post(url=url,
data=payload,
headers=headers,
auth=HTTPBasicAuth(app.config['USERNAME'], app.config['PASSWORD']),
verify=False)
Userlevel 3
OK great I'm glad you figured it out and let us know!

Reply