08-03-2016 07:33 AM - edited 03-01-2019 04:30 AM
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.
08-03-2016 07:57 AM
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--
08-03-2016 08:13 AM
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)
08-03-2016 08:22 AM
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)
08-03-2016 08:25 AM
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)
08-03-2016 08:52 AM
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))
08-04-2016 01:05 AM
Brilliant
it works, thanks very much.
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:
This community is intended for developer topics around Data Center technology and products. If you are looking for a non-developer topic about Data Center, you might find additional information in the Data Center and Cloud community