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

data model for upload config file to APIC-EM for PNP

francisyiu
Level 1
Level 1

please tell me the data model (fields) to upload config file to APIC-em. is the following correct:

in version 1.2 want to use API to upload config file for PNP,

found can use ""POST /file/config"

but the API doc does not show anything about the data model, that is how to format the data/header.

please any information about it, or I should use another API.

6 Replies 6

Joe Clarke
Cisco Employee
Cisco Employee

Yes, POST /file/config.  What language are you programming in?  Many have libraries or helpers to do file uploads.  From a raw standpoint, the headers and request look like:

POST /apic/api/v1/file/config HTTP/1.1

Host: apic-em.company.com

Connection: keep-alive

Content-Length: 87291

Pragma: no-cache

Cache-Control: no-cache

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary3B3MLAy0FwOwzuz7

scope: ALL

Accept: application/json, text/javascript, */*; q=0.01

------WebKitFormBoundary3B3MLAy0FwOwzuz7

Content-Disposition: form-data; name="fileUpload"; filename="rtr1.cfg"

Content-Type: application/octet-stream

------WebKitFormBoundary3B3MLAy0FwOwzuz7--

thanks for you prompt response I am using python, can you clarify more, not a experience programmer.

so in the REST API the data body is:

(   onnection: keep-alive,

   Content-Length: 87291,

   Pragma: no-cache,

   Cache-Control: no-cache)

header = ( Content-Type: multipart/form-data;

   boundary=----WebKitFormBoundary3B3MLAy0FwOwzuz7'

scope: ALL,

Accept: application/json, text/javascript, */*; q=0.01)

Assuming you're using the requests module, this should work for you:

url = "https://apic-em.company.com/api/v1/file/config"

file = { 'fileUpload':open('rtr1.cfg', 'rb') }

res = requests.post(url, files=file)

Whoops, I should have pasted this version to give the file a better name:

url = "https://apic-em.company.com/api/v1/file/config

file = { 'rtr1.cfg':open('rtr1.cfg', 'rb') } 

res = requests.post(url, files=file)

Get a token and the following should work:

ticket = get_X_auth_token()

headers = {"content-type" : "application/json","X-Auth-Token": ticket}

# need to change source and destination IP to the one you like to trace

name = "/TFTP-Root/2911cfg.bin" # your file

content = open(name, "r")

post_url = "https://"+apicem_ip+"/api/v1/file/config"

files = {'fileUpload': (name, content)}

headers = {"X-Auth-Token": ticket}

r = requests.post(post_url, headers=headers,files=files,verify=False)

response_json = r.json()

print ("POST Status: ",r.status_code)

print (json.dumps(response_json,indent=4))

Brilliant

it works, thanks very much.