Dashboard API - Update a VLAN does not work from bat or ps1

Solved
AndreasE
Getting noticed

Dashboard API - Update a VLAN does not work from bat or ps1

I tried to use the following command from both .bat and .ps1 types of batch files (Windows CMD and Powershell), but they always throw error "Bad request: There was a problem in the JSON you submitted":

 

\bin>.\curl.exe --verbose -H "X-Cisco-Meraki-API-Key:~~~ed4c95773f7" -H "Content-Type:application/json" -X PUT --data-binary '{"applianceIp":"172.25.240.49","subnet":"172.25.240.48/29"}' "https://api.meraki.com/api/v0/networks/N_682~~~86331/vlans/801"
*   Trying 209.206.57.36...
* TCP_NODELAY set
* Connected to api.meraki.com (209.206.57.36) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: ~~~\bin\curl-ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* NPN, negotiated HTTP1.1
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Next protocol (67):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: OU=Domain Control Validated; CN=*.meraki.com
*  start date: Aug 16 20:21:40 2016 GMT
*  expire date: Sep 16 20:57:39 2019 GMT
*  subjectAltName: host "api.meraki.com" matched cert's "*.meraki.com"
*  issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
*  SSL certificate verify ok.
> PUT /api/v0/networks/N_682~~~86331/vlans/801 HTTP/1.1
> Host: api.meraki.com
> User-Agent: curl/7.60.0
> Accept: */*
> X-Cisco-Meraki-API-Key:~~~ed4c95773f7
> Content-Type:application/json
> Content-Length: 53
>
* upload completely sent off: 53 out of 53 bytes
< HTTP/1.1 400 Bad Request
< Server: nginx
< Date: Fri, 08 Jun 2018 14:54:34 GMT
< Content-Type: */*; charset=utf-8
< Content-Length: 58
< Connection: keep-alive
< X-Request-Id: f209630c73f04174371cabe2f2d4ed74
< X-Runtime: 0.001298
< X-Rack-Cache: invalidate, pass
<
Bad request: There was a problem in the JSON you submitted
* Connection #0 to host api.meraki.com left intact

 

When using from Postman, everything works fine, so I cannot deduct the error reason from there.

 

With Kind Regards 

Andreas Englisch

1 Accepted Solution
HodyCrouch
Building a reputation

I think you are being thwarted by your shell, probably because of the quotation marks.  The hint is in the verbose output from curl.

 

Content-Length: 53

 

However, your JSON is 59 characters long.

 

I'm sitting at a Mac, and when I use your command line, curl attempts to send the correct 59 characters (I can't see if it will actually work, because I'm not going to mess with VLANs right now).

 

You can try backslash-escaping the double-quotes or use the -d option in curl to read the post data from a file.

 

curl --verbose -H "X-Cisco-Meraki-API-Key:~~~ed4c95773f7" -H "Content-Type:application/json" -X PUT --dat-binary "@postdata.txt" "https://api.meraki.com/api/v0/networks/N_682~~~86331/vlans/801"

 

View solution in original post

2 Replies 2
HodyCrouch
Building a reputation

I think you are being thwarted by your shell, probably because of the quotation marks.  The hint is in the verbose output from curl.

 

Content-Length: 53

 

However, your JSON is 59 characters long.

 

I'm sitting at a Mac, and when I use your command line, curl attempts to send the correct 59 characters (I can't see if it will actually work, because I'm not going to mess with VLANs right now).

 

You can try backslash-escaping the double-quotes or use the -d option in curl to read the post data from a file.

 

curl --verbose -H "X-Cisco-Meraki-API-Key:~~~ed4c95773f7" -H "Content-Type:application/json" -X PUT --dat-binary "@postdata.txt" "https://api.meraki.com/api/v0/networks/N_682~~~86331/vlans/801"

 

Hi HodyCrouch,

 

tx for your reply. The first recommendation indeed solved my issue. (The second probably wouold do so as well, but then I would need to create 80 short files which makes it much more effort.)

 

Tx again,

 

AndreasE

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.