cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1526
Views
0
Helpful
2
Replies

Prime api/v4 : how to delete/sycn/add device

erdemk
Level 1
Level 1

Dear community,

 

I couldn't succeed to use Prime API and If this is not the right place for prime API question, please forward me to right place.

 

I can retrieve device list through API from Prime using python, but i couldn't succeed to delete/sync/add devices. Any help or guidance is appreciated. Working python or any other example would be very good if possible.

 

I get "Unrecognized token" error in SYNC-DEVICE and DELETE-DEVICE use cases, although i am using the payload from documentation. And i am getting 'Access is denied to "+"Prime Infrastructure"' error, although my API user have NBI read/write/credentials rights.

 

prime version : 3.7.0

api version :v4

 

note: header is same for all api use0cases : 

headers = {
'Authorization': 'Basic Y21kYjpFY3oyMDIwVGxjc3Q=', 'Content-Type': 'application/json'
}

 

USE CASE 1/       SYNC DEVICE

 

url = "https://10.100.100.134/webacs/api/v4/op/devices/syncDevices"
payload = {
"syncDevicesDTO" : {
"devices" : {
"device" : [ {
"address" : "10.28.31.32"
} ]
}
}
}
response = requests.request("POST", url, headers=headers, data=payload, verify=False)
response.text :

<?xml version="1.0" ?>\n
<errorDocument>\n
<httpResponseCode>500</httpResponseCode>\n
<httpMethod>POST</httpMethod>\n
<message>com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'syncDevicesDTO\': was expecting (\'true\', \'false\' or \'null\')\n
at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 16]</message>\n
<exception>javax.ws.rs.InternalServerErrorException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'syncDevicesDTO\': was expecting (\'true\', \'false\' or \'null\')\n
at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 16]</exception>\n
<uriPath>op/devices/syncDevices</uriPath>\n
<queryParams>{}</queryParams>\n</errorDocument>'

 

USE CASE 2/ DELETE DEVICE by removaljob

url = "https://10.100.100.134/webacs/api/v4/op/devices/removalJob"
payload = {
"removalJobParamsDTO" : {
"deleteAPs" : true,
"ipAddressList" : {
"ipAddressList" : [ {
"address" : "11.11.11.12"
} ]
}
}
}
response = requests.request("POST", url, headers=headers, data=payload, verify=False)
response.text :

'<?xml version="1.0" ?>\n

<errorDocument>\n <httpResponseCode>500</httpResponseCode>\n

<httpMethod>POST</httpMethod>\n

<message>com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'removalJobParamsDTO\': was expecting (\'true\', \'false\' or \'null\')\n

at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 21]</message>\n

<exception>javax.ws.rs.InternalServerErrorException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'removalJobParamsDTO\': was expecting (\'true\', \'false\' or \'null\')\n

at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 21]</exception>\n

<uriPath>op/devices/removalJob</uriPath>\n <queryParams>{}</queryParams>\n</errorDocument>'

 

USE CASE 2b/ DELETE DEVICE 

url = "https://10.100.100.134/webacs/api/v2/op/devices/deleteDevices"
payload = {
"deviceDeleteCandidates" : {
"ipAddresses" : {
"ipAddress" : [ "11.11.11.12" ]
}
}
}
response = requests.request("PUT", url, headers=headers, data=payload, verify=False)
response.text :

<?xml version="1.0" ?>\n
<errorDocument>\n <httpResponseCode>500</httpResponseCode>\n
<httpMethod>PUT</httpMethod>\n
<message>com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'deviceDeleteCandidates\': was expecting (\'true\', \'false\' or \'null\')\n
at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 24]</message>\n
<exception>javax.ws.rs.InternalServerErrorException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'deviceDeleteCandidates\': was expecting (\'true\', \'false\' or \'null\')\n
at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 1, column: 24]</exception>\n
<uriPath>op/devices/deleteDevices</uriPath>\n
<queryParams>{}</queryParams>\n</errorDocument>'

 

USE CASE 3/ ADD DEVICE 

url = "https://10.100.100.134/webacs/api/v4/op/devices/bulkImport"

payload= {
"devicesImport" : {
"devices" : {
"device" : [ {
"cliEnablePassword" : "String value",
"cliPassword" : "String value",
"cliRetries" : "String value",
"cliTimeout" : "String value",
"cliUsername" : "String value",
"credentialProfileName" : "String value",
"httpConfigPassword" : "String value",
"httpConfigUsername" : "String value",
"httpMonitorPassword" : "String value",
"httpMonitorUsername" : "String value",
"httpPort" : "String value",
"httpServer" : "String value",
"ipAddress" : "11.11.11.11",
"networkMask" : "255.255.255.0",
"protocol" : "String value",
"snmpCommunity" : "XXXXX",
"snmpPort" : "String value",
"snmpReadCommunity" : "String value",
"snmpRetries" : "String value",
"snmpTimeout" : "String value",
"snmpVersion" : "String value",
"snmpWriteCommunity" : "String value",
"snmpv3AuthPassword" : "String value",
"snmpv3AuthType" : "String value",
"snmpv3PrivacyPassword" : "String value",
"snmpv3PrivacyType" : "String value",
"snmpv3UserName" : "String value",
"udf" : "",
}, ]
}
}
}

response = requests.request("POST", url, headers=headers, data=payload, verify=False)

response.text :

'\n\n\n\n\n\n\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n<link rel="stylesheet" href="/webacs/styles/wcs.css" type="text/css">\n<script type="text/javascript">\nfunction windowTitle()\n{\n\t var productName = \'Prime Infrastructure\';\n\t if(productName=="Prime Infrastructure"){\n\t parent.document.title ="Access is denied to "+"Prime Infrastructure";\n\t }else if(productName=="Evolved Programmable Network Manager"){\n\t parent.document.title ="Access is denied to"+"EPN Manager";\n\t }\n}\n</script>\n</head>\n<body onload="windowTitle();" class="popup" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n\n\n<table width="100%" height="62" border="0" cellspacing="0" cellpadding="0">\n <tr>\n <td height="62" width="180">&nbsp;</td>\n <td valign="bottom" style="background-color:#ffffff;>\n <div class="mainMenu">\n <table width="100%" border="0" cellspacing="0" cellpadding="0">\n <tr>\n <td height="43" valign="bottom">\n </td>\n </tr>\n <tr>\n <td bgcolor="FFFFFF" height="19">&nbsp; </td>\n </tr>\n </table>\n </div>\n </td>\n </tr>\n <tr>\n <td valign="top">\n <div class="navBar"> &nbsp; </div>\n </td>\n <td valign="top">\n <div class="content">\n <table>\n <tr>\n <td class="pageTitleProp">\n\t\t \n\t\t\t\t\t\t\t\tAccess is denied to \n\t\t\t\t\t\t\t\tPrime Infrastructure.\n\t\t\t \n <br>Please contact the network administrator</br>\n </td>\n </tr>\n </table>\n </div>\n </td>\n </tr>\n</table>\n<div class="alarms"> &nbsp;</div>\n</body>\n</html>\n\n'

 

 

2 Replies 2

erdemk
Level 1
Level 1

any guidance is much appreciated.

TAC doesn't support api questions.. i have asked to web my developer colleague as he knows more on apis, no success..

 

Do i need to post this in any other section in community.cisco.com?

 

thanks in advance, and regards..

Olga Bozhko
Cisco Employee
Cisco Employee

Hello,

Try add .json in the end of the url, like "/op/devices/syncDevices.json", "/op/devices/removalJob.json", "/op/devices/bulkImport.json" (please note PUT devices/deleteDevices API is deprecated and not recommended to use).
Also, there are some extra commas in the bulkImport's payload (maybe, simply a consequence of copying).

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: