1

I've been reading about Cisco ACI Automation with cURL here and trying to follow the same steps.

Unfortunately, the code doesn't work on cURL. I'm getting the following error.

C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{"aaaUser":{"attributes":{"name":"user007","pwd":"password007"}}}'
{"totalCount":"1","imdata":[{"error":{"attributes":{"code":"400","text":"JSON parsing failed - incomplete attribute value at line: 1"}}}]}
C:\>

However, when I test the same code using Postman, it's working like a charm. What was wrong with the curl command?

Note: I did not put -c cookie.txt in this example as I'm getting the same error even if it's there.

Desired Output

Getting proper HTTP 200 response, not 400 Bad Request ..

Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43

2 Answers2

3

You need first to login:

curl -X POST -k https://APIC_IP_ADDRESS/api/aaaLogin.xml -d '<aaaUser name="USERNAME" pwd="PASSWORD"/>' -c cookie.txt

The APIC controller returns a token stored in a cookie. It will last for 5 minutes. You must use this cookie to run any following REST API.

For example the REST API that creates a new Tenat, a new Application Profile and a new EPG will look like this:

curl -b cookie.txt -X POST -k https://APIC_IP_ADDRESS/api/node/mo/uni.xml -d '<polUni> <fvTenant name="TENANT-NAME" descr="TENANT-NAME-DESC" status=""> <fvAp name="APP-PROF-NAME">   <fvAEPg name="NEW-EPG-NAME" > </fvAEPg> </fvAp> </fvTenant> </polUni>' -c cookie.txt
gaetano
  • 865
  • 1
  • 15
  • 29
-1

You need to escape the double quotes (")

C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{\"aaaUser\":{\"attributes\":{\"name\":\"user007\",\"pwd\":\"password007\"}}}'

In fact, you can even use the double quotes for user and password only:

C:\>curl -X POST -k https://x.x.x.x/api/aaaLogin.json -d '{aaaUser:{attributes:{name:\"user007\",pwd:\"password007\"}}}'

The reason you need to escape the \" is because curl will remove them when constructing and sending the POST message. This is a capture from whireshark: whireshark capture

Reference: https://stackoverflow.com/a/15828662/147637

msdaniluk
  • 1
  • 1