cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
810
Views
0
Helpful
3
Replies

403 response while adding device to dna sandbox

loluolaoye
Level 1
Level 1

Hello, I am trying to add a new device using the DNA sandbox but I keep getting a 403 response. Is there something wrong with my code?

import requests
import json
from auth_token import get_token

device_endpoint = "/dna/intent/api/v1/network-device"

headers = {"Content-Type""application/json""X-auth-token"get_token('devnetuser''Cisco123!')}


payload = {
    "ipAddress": ["192.168.23.34"],
    "snmpVersion""v2",
    "snmpROCommunity""readonly",
    "snmpRWCommunity""readwrite",
    "snmpRetry""1",
    "snmpTimeout""60",
    "cliTransport""ssh",
    "userName""Loluwa",
    "password""lolu123!",
    "enablePassword""lolu123456",
}

response = requests.post(f'{url}{device_endpoint}'json=payload, headers=headers)

print(response)
 
Please help
3 Replies 3

Mike.Cifelli
VIP Alumni
VIP Alumni
Please try changing your payload ipAddress to the following:
from this:
"ipAddress": ["192.168.23.34"],
to this:
"ipAddress": "192.168.23.34",

I believe the IpAddress formatting is ok. If you use it differently, you get:

 

"Reason: data.ipAddress must be array or null"

This has worked for me.  Excluding some code, but try adding some additional required fields in your payload as I think that is your issue.  See below:

def add_device(IP_ADDR):
data = get_token()
print "***************************"

API_URL = 'https://<dnac>/dna/intent/api/v1/network-device/'
AUTH = {
'X-Auth-Token' : data,
'Content-type' : 'application/json'
}
NAD_OBJ ={
"ipAddress" :[
IP_ADDR
],
"type" : "NETWORK_DEVICE",
"computeDevice" : False,
"snmpVersion" : "V3",
"snmpUserName" : "<user>",
"snmpMode" : "RW",
"snmpAuthProtocol" : "SHA",
"snmpAuthPassphrase" : "<pass>",
"snmpPrivProtocol" : "AES128",
"snmpPrivPassphrase" : "<pass>",
"snmpRetry" : "3",
"snmpTimeout" : "5",
"cliTransport" : "SSH",
"userName" : "<youruser>",
"password" : "<yourpw>",
"enablePassword" : "<yourpw>",
}
r = requests.post(url=API_URL, headers=AUTH, verify=False, json=NAD_OBJ)
print r.text
print "SDA Device", r.reason 

 HTH!