cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1188
Views
5
Helpful
4
Replies

API call to ACI

chemudupaty
Level 1
Level 1

I am planning to see if I can import a csv files for creating multiple VPC's and assign them to physical port. I tried individually using postman variables defined in pre-request script and it worked. Now, i am trying to see if I can configure multiple of them same time. 

 

Thanks.

4 Replies 4

kkhlebop
Cisco Employee
Cisco Employee

Can you share your postman by converting your postman calls to python script or curl using postman features, so can follow along and see if understand your issue properly. 

 

Here is how to convert it to code (python or curl or many other languages): https://stackoverflow.com/questions/49432735/converting-a-postman-request-to-curl

import http.client
import json

conn = http.client.HTTPSConnection("{{apic}}")
payload = "payload{\r\n \"infraHPortS\": {\r\n \"attributes\": {\r\n \"dn\": \"uni/infra/accportprof-{{LEAF_INT_PROF}}/{{hports-PORT-1-typ-range}}\",\r\n \"name\": \"{{PORT-1}}\",\r\n \"rn\": \"{{hports-PORT-1-typ-range}}\",\r\n \"status\": \"created,modified\"\r\n },\r\n \"children\": [\r\n {\r\n \"infraPortBlk\": {\r\n \"attributes\": {\r\n \"dn\": \"uni/infra/accportprof-{{LEAF_INT_PROF}}/{{hports-PORT-1-typ-range}}/portblk-block2\",\r\n \"fromPort\": \"{{F-Port}}\",\r\n \"toPort\": \"{{T-Port}}\",\r\n \"name\": \"block2\",\r\n \"rn\": \"portblk-block2\",\r\n \"status\": \"created,modified\"\r\n },\r\n \"children\": []\r\n }\r\n },\r\n {\r\n \"infraRsAccBaseGrp\": {\r\n \"attributes\": {\r\n \"tDn\": \"uni/infra/funcprof/accbundle-{{VPC_HOST_POL_GRP}}\",\r\n \"status\": \"created,modified\"\r\n },\r\n \"children\": []\r\n }\r\n }\r\n ]\r\n }\r\n}"
headers = {
'Content-Type': 'application/json',
'Cookie': 'APIC-cookie=eyJhbGciOiJSUzI1NiIsImtpZCI6IjVyejc2MjViMWg1cnJyMGM3ejc5emhhbnAwdGV1YnoyIiwidHlwIjoiand0In0.eyJyYmFjIjpbeyJkb21haW4iOiJhbGwiLCJyb2xlc1IiOjAsInJvbGVzVyI6MX1dLCJpc3MiOiJBQ0kgQVBJQyIsInVzZXJuYW1lIjoiYWRtaW4iLCJ1c2VyaWQiOjE1Mzc0LCJ1c2VyZmxhZ3MiOjAsImlhdCI6MTYyNDY4MDY0NSwiZXhwIjoxNjI0NjgxMjQ1LCJzZXNzaW9uaWQiOiJSMmJwRXdPUVRKV0c3ZWhRcy93L1BBPT0ifQ.juzVBmDpEFblcGrPVm4K_ztY3QrDx_URtacJifEvHGMPTBgM3zsy_jXzvrNTXNZiK4QEB66BRETDrKucVVuIZOW5Q4hPqqemy4jsM-LnYOF2v1NEbWwkvu6uTDwLBcgvYeB8QOI4s6Mrr17emKVU_eMpSotZUh7CDhMkXUv7qOyGQZkWIqw4AF13BzyqiMHG6CmhY4PssInxVmwyCz_ubcgpnSKpMZcbaaJIWoUv-2-6EMnmqnlI-p1McnrLClYYezC-US7BpjXvxzJe123pPBZBgZ3-mV-ccEdKghEoRnPjjphjdSHKQDeTtx8R8cImBrDehBPCJC1wVDC785RgQA'
}
conn.request("POST", "/api/node/mo/uni/infra/accportprof-{{LEAF_INT_PROF}}/{{hports-PORT-1-typ-range}}.json", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))


Below is the Spreadsheet with the variables I am passing and it fails. If I pass the variables individually it works just doesn't work with csv.



Thanks,

Usha

Alexander Stevenson
Cisco Employee
Cisco Employee

@kkhlebop  ^^^ please

I was able to figure this out. I had to change the variables in my csv file. Thanks!