cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
132
Views
1
Helpful
2
Replies

unable to retrieve UC certificate info using API

cxu21
Level 1
Level 1

I am trying to retrieve certficate information against the Cisco sandbox collaboration 14.0.

Here is my python code

def getTomcat(hostname, username, password):
body = {"service": "CAPF"},
response = requests.get(
url=''.join(('https://', hostname, '/platformcom/api/v1/certmgr/config/csr')),
headers= {"Content-Type": "application/json"},
auth= (username, password),
json= body,
verify=False
)
print(response)
print(response.json())
#
if __name__=="__main__":
getTomcat("10.10.20.1", "admin","pw")

Here is the reference I used https://developer.cisco.com/docs/certificate-management/#!api-reference

It returned error code 400 as below

<Response [400]>
{'key': 400, 'messages': ['Invalid Service Name!'], 'trackingID': 'UC_5680397f-0fa9-4271-bcc2-0e194de0b5a6'}

Is there anything else I am missing?

1 Accepted Solution

Accepted Solutions

Thank you for your reply.

The comma behind the service parameter is one of the problems, the python won't run if it is there, I do not know why it was there, probably it is a typo when I post the script.

The invalid service name error is related to the variable name in the get request, if I change "json" to "params", it will work.

response = requests.get(
url=''.join(('https://', hostname, '/platformcom/api/v1/certmgr/config/csr')),
headers= {"Content-Type": "application/json"},
auth= (username, password),
params= body,
verify=False
)

 

View solution in original post

2 Replies 2

Not an expert here, looking atthe error message you received, it seems that the service parameter in the request body is not being recognized by the API. It looks like you are passing the service parameter as a separate dictionary in the request body, instead of as a key-value pair. I updated the service parameter and now this is passed as a key-value pair in the body dictionary, which should be correctly interpreted by the API.

Hope this helps.

import requests

def getTomcat(hostname, username, password):
    body = {"service": "CAPF"}
    response = requests.get(
                            url=''.join(('https://', hostname, '/platformcom/api/v1/certmgr/config/csr')),
                            headers= {"Content-Type": "application/json"},
                            auth= (username, password),
                            json= body,
                            verify=False
                            )
    print(response)
    print(response.json())
#
if __name__=="__main__":
     getTomcat("10.10.20.1", "admin","pw")

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thank you for your reply.

The comma behind the service parameter is one of the problems, the python won't run if it is there, I do not know why it was there, probably it is a typo when I post the script.

The invalid service name error is related to the variable name in the get request, if I change "json" to "params", it will work.

response = requests.get(
url=''.join(('https://', hostname, '/platformcom/api/v1/certmgr/config/csr')),
headers= {"Content-Type": "application/json"},
auth= (username, password),
params= body,
verify=False
)