04-09-2024 11:42 PM
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?
Solved! Go to Solution.
04-13-2024 04:42 PM
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
)
04-10-2024 03:09 AM
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")
04-13-2024 04:42 PM
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
)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide