cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
903
Views
2
Helpful
6
Replies

Can any one help with this error from DNAC API (add device to site)

AaronStreet
Level 1
Level 1

Hi, 

I am trying the following API call from pything and the responce i get is below,  can any one tell me why it is failling, it does give a 202 reponce code with the message "message" : "The request has been accepted for execution" but then it comes back with the following.  

Thank you 

{

  "bapiKey": "98a8-aa5e-40cb-b90b",

  "bapiName": "Assign Device To Site",

  "bapiExecutionId": "79cf4eed-081f-4f24-a157-f7ba5764e7c4",

  "startTime": "Mon Nov 27 16:15:58 UTC 2023",

  "startTimeEpoch": 1701101758666,

  "endTime": "Mon Nov 27 16:15:58 UTC 2023",

  "endTimeEpoch": 1701101758697,

  "timeDuration": 31,

  "status": "FAILURE",

  "bapiError": "{\"status\":\"False\"}",

  "runtimeInstanceId": "DNACP_Runtime_907770e3-8857-435b-8725-0bfd5c8eaccb"

}

 

1 Accepted Solution

Accepted Solutions

Awesome, Yes if you are specifying the json parameter when making the POST request, you don't need to explicitly convert the payload to JSON yourself using json.dumps().

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

View solution in original post

6 Replies 6

@AaronStreet odd message, the 202 status means "I've accepted this request and will process it in the future, but I'm not committing to provide the outcome status immediately."

Some key things to note from your error

  • status: "FAILURE" - overall status of the API call is failure
  • bapiError: "{\\"status\\":\\"False\\"}" - raw error returned by the API. It is returning a JSON object with status set to "False", indicating there was an error in processing your request

Can you share the code you are using and the API endpoint/url?

Hope this helps.

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

Hi, see below, the DNAC and Token variables work ok for other API calls in the same script such as "get sites", the site variable is a building site id in formate "349f9ffc-8d46-xxxx-xxxx-xxxxxxxxxx2d", and the device IP is the managment IP. 

Under the GUI i can see the device in question is showing and "unasigned" 

the output of the print statments are these (replaced some parts with xx)  

<sitename> 89xxxxxx-xxxx-xxxx-xxxx-1e164cf904d4 10.80.x.x
dnac-eu.corp.comt
{"device": [{"ip": "10.80.x.x"}]}
{
"executionId" : "f7224742-5ed0-45ef-9426-0a4bd6c59195",
"executionStatusUrl" : "/dna/platform/management/business-api/v1/execution-status/f7224742-5ed0-45ef-9426-0a4bd6c59195",
"message" : "The request has been accepted for execution

 

def add_device_to_site(dnac, token,site,deviceIP

    device_list = {
    "device": [
        {
            "ip": deviceIP
        }
           ]
    }
   

   
    url = 'https://{}/dna/intent/api/v1/assign-device-to-site/'.format(dnac['host']) +site[4]+'/device'
    print(site[0], "  " ,site[4], "   ", deviceIP)
    print (dnac['host'])
    headers["x-auth-token"] = token
    data=json.dumps(device_list)
    response = requests.post(url, headers=headers, verify=False, json = data)    
    print (response.text)

Hi, 

I think it was that i dont need the data=json.dumps(device_list), as i already have it in json format. 

commenting out this seems to fix it, sorry and thank you for taking the time to look at this for me. 

Awesome, Yes if you are specifying the json parameter when making the POST request, you don't need to explicitly convert the payload to JSON yourself using json.dumps().

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

balaji.bandi
Hall of Fame
Hall of Fame

here is the correct syntax to be used :

https://developer.cisco.com/docs/dna-center/#!add-device

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

AaronStreet
Level 1
Level 1

Thank you for your help, a slightly different question, when creating the script in 2.3.5.4 the responce to gettin list of network devices "https://{}/api/v1/network-device?location=null&family=Switches and Hubs&series=Cisco Catalyst 9300 Series Switches".format(dnac['host']" the location and locationname always comes back as "null" even when the device is assigned to a site/floor? 

has any one else seen this?