Add Network Object using cURL on Windows

ddawson100
Here to help

Add Network Object using cURL on Windows

I'm trying to add policy objects using cURL on Windows. I keep getting error "Bad request: There was a problem in the JSON you submitted." I don't have regular access to a Linux machine but when I run this command there it's working. There are a few clients and a lot of entries I need to add and I need to do this work from a Windows computer. What am I doing wrong here?

 

From the Linux machine I use: curl -L -H 'X-Cisco-Meraki-API-Key: redacted' -H "Content-Type: application/json" -X POST --data-binary '{"name":"Test Object","category":"network", "type": "cidr","cidr":"[ip4 address'","groupIds":[]}' 'https://api.meraki.com/api/v1/organizations/[redacted]/policyObjects'

 

and it works:

 

From the Windows machine I use: curl -L -H "X-Cisco-Meraki-API-Key:[redacted]" -H "Content-Type:application/json" -X POST --data-binary {"name":"Test Object","category":"network","type":"cidr","cidr":"ip4 address","groupIds":"[]"} https://api.meraki.com/api/v1/organizations/[redacted]/PolicyObjects -v

 

and I get verbose results here:


Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 209.206.54.142...
* TCP_NODELAY set
* Connected to api.meraki.com (209.206.54.142) port 443 (#0)
* schannel: SSL/TLS connection with api.meraki.com port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 185 bytes...
* schannel: sent initial handshake data: sent 185 bytes
* schannel: SSL/TLS connection with api.meraki.com port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with api.meraki.com port 443 (step 2/3)
* schannel: encrypted data got 4017
* schannel: encrypted data buffer: offset 4017 length 4096
* schannel: sending next handshake data: sending 93 bytes...
* schannel: SSL/TLS connection with api.meraki.com port 443 (step 2/3)
* schannel: encrypted data got 258
* schannel: encrypted data buffer: offset 258 length 4096
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with api.meraki.com port 443 (step 3/3)
* schannel: stored credential handle in session cache
> POST /api/v1/organizations/[redacted]/PolicyObjects HTTP/1.1
> Host: api.meraki.com
> User-Agent: curl/7.55.1
> Accept: */*
> X-Cisco-Meraki-API-Key:[redacted]
> Content-Type:application/json
> Content-Length: 74
>
* upload completely sent off: 74 out of 74 bytes
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 385
* schannel: encrypted data buffer: offset 385 length 103424
* schannel: decrypted data length: 356
* schannel: decrypted data added: 356
* schannel: decrypted data cached: offset 356 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 356 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 356
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 400 Bad Request
< Server: nginx/1.21.4
< Date: Mon, 06 Dec 2021 21:15:15 GMT
< Content-Type: */*; charset=utf-8
< Content-Length: 58
< Connection: keep-alive
< X-Request-Id: 7373e325bb2d286c34a5073594e50c08
< X-Runtime: 0.001559
< Strict-Transport-Security: max-age=15552000; includeSubDomains
<
Bad request: There was a problem in the JSON you submitted* Connection #0 to host api.meraki.com left intact

 

1 Reply 1
PaulF
Meraki Employee
Meraki Employee

I've just spent the best part of two hours with Windows and CURL, and, FINALLY had some success.

 

However, I'm not going to be able to EXACTLY answer your question, but wanted to help you on the way:

 

curl --get -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Cisco-Meraki-API-Key: 65656565656565656565" https://api.meraki.com/api/v1/organizations

 

Is a simple "Get Orgs" API call

 

The issue I see with your code is that Windows is painfully picky with escaping double quotes and stuff. I visibly grew old trying to get it to work, and gave up.

 

What I did achieve, however, was to put the body into a file called body.json on my desktop. Nothing is escaped in here, other than the JSON I'm included 

 

Screenshot 2023-01-31 at 4.36.00 PM.png

 

And to simplify things, I then issued the following command:

 

curl https://api.meraki.com/api/v1/networks/N_56565656565656565/webhooks/payloadTemplates --header "Content-Type: application/json" --header "Accept: application/json" --header "X-Cisco-Meraki-API-Key: 5656565656565656" --data "@C:\Users\Meraki Admin\Desktop\body.json"

 

MUCH easier. If you literally replicated EVERYTHING above and placed:

 

 {"name":"Test Object","category":"network","type":"cidr","cidr":"ip4 address","groupIds":"[]"}

 

 into the body.json you should have some success

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.