[SOLVED] Problems with JSON parsing errors

I want to test setting a variable to a value. My device is called mqttdata and the variable is called number.

My curl command line is:
curl -X POST -H “X-Auth-Token:BBFF-xxxxxxxxxxxxxxxxxxxxxxxxxxx” -H “Content-Type:application/json” -d ‘{“value”: 59}’ https://things.ubidots.com/api/v1.6/devices/mqttdata/number/values -vvv

Using CURL from windows CMD I cannot solve the following error and of course the device variable is not changing.

  • upload completely sent off: 12 out of 12 bytes
  • Mark bundle as not supporting multiuse
    < HTTP/1.1 400 Bad Request
    < Server: nginx
    < Date: Wed, 04 Dec 2019 17:09:44 GMT
    < Content-Type: application/json
    < Transfer-Encoding: chunked
    < Vary: Accept, Origin, Cookie
    < Allow: GET, POST, HEAD, OPTIONS
    <
    {“detail”: “JSON parse error - Expecting value: line 1 column 1 (char 0)”}* Connection #0 to host things.ubidots.com left intact

Can anyone help please?

Hello @CeJay,

The bad request (400) is generated because the double quotation marks used in the request are not the proper ones.

Try the following request to handle your data with Ubidots:

curl -X POST -H "X-Auth-Token:BBFF-xxxxxxxxxxxxxxxxxxx" -H "Content-Type:application/json" -d '{"value": 59}' https://industrial.api.ubidots.com/api/v1.6/devices/mqttdata/number/values -vvv

Server response expected:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 169.55.61.243:443...
* TCP_NODELAY set
* Connected to industrial.api.ubidots.com (169.55.61.243) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=industrial.api.ubidots.com
*  start date: Nov 11 20:11:54 2019 GMT
*  expire date: Feb  9 20:11:54 2020 GMT
*  subjectAltName: host "industrial.api.ubidots.com" matched cert's "industrial.api.ubidots.com"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> POST /api/v1.6/devices/mqttdata/number/values HTTP/1.1
> Host: industrial.api.ubidots.com
> User-Agent: curl/7.65.3
> Accept: */*
> X-Auth-Token:BBFF-xxxxxxxxxxxxxxxxxxx
> Content-Type:application/json
> Content-Length: 13
> 
* upload completely sent off: 13 out of 13 bytes
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Server: nginx
< Date: Wed, 04 Dec 2019 19:58:38 GMT
< Content-Type: application/json
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: https://industrial.api.ubidots.com/api/v1.6/values/5de80fee73efc3287211cb65
< Vary: Accept, Origin, Cookie
< Allow: GET, POST, HEAD, OPTIONS
< 
* Connection #0 to host industrial.api.ubidots.com left intact
{"url": "https://industrial.api.ubidots.com/api/v1.6/values/5de80fee73efc3287211cb65", "value": 59.0, "timestamp": 1575489518079, "context": {}, "created_at": "2019-12-04T19:58:38.079391Z"}

All the best,
Maria H.

Hi Maria,

I tried your post. I added the token and changed the URL as I am using STEM version. I got :((

C:\Users\Chris>curl -X POST -H “X-Auth-Token:BBFF-yrKRTfH5RAVrgO3BDRUjOXZtHpT0Kb” -H “Content-Type:application/json” -d ‘{“value”: 59}’ https://things.ubidots.com/api/v1.6/devices/mqttdata/number/values -vvv
curl: (3) [globbing] unmatched close brace/bracket in column 3
Note: Unnecessary use of -X or --request, POST is already inferred.

  • Trying 50.23.124.68…
  • TCP_NODELAY set
  • Connected to things.ubidots.com (50.23.124.68) port 443 (#0)
  • schannel: SSL/TLS connection with things.ubidots.com port 443 (step 1/3)
  • schannel: checking server certificate revocation
  • schannel: sending initial handshake data: sending 183 bytes…
  • schannel: sent initial handshake data: sent 183 bytes
  • schannel: SSL/TLS connection with things.ubidots.com port 443 (step 2/3)
  • schannel: failed to receive handshake, need more data
  • schannel: SSL/TLS connection with things.ubidots.com port 443 (step 2/3)
  • schannel: encrypted data got 3057
  • schannel: encrypted data buffer: offset 3057 length 4096
  • schannel: sending next handshake data: sending 126 bytes…
  • schannel: SSL/TLS connection with things.ubidots.com port 443 (step 2/3)
  • schannel: encrypted data got 51
  • schannel: encrypted data buffer: offset 51 length 4096
  • schannel: SSL/TLS handshake complete
  • schannel: SSL/TLS connection with things.ubidots.com port 443 (step 3/3)
  • schannel: stored credential handle in session cache

POST /api/v1.6/devices/mqttdata/number/values HTTP/1.1
Host: things.ubidots.com
User-Agent: curl/7.55.1
Accept: /
X-Auth-Token:BBFF-yrKRTfH5RAVrgO3BDRUjOXZtHpT0Kb
Content-Type:application/json
Content-Length: 8

  • upload completely sent off: 8 out of 8 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 317
  • schannel: encrypted data buffer: offset 317 length 103424
  • schannel: decrypted data length: 288
  • schannel: decrypted data added: 288
  • schannel: decrypted data cached: offset 288 length 102400
  • schannel: encrypted data buffer: offset 0 length 103424
  • schannel: decrypted data buffer: offset 288 length 102400
  • schannel: schannel_recv cleanup
  • schannel: decrypted data returned 288
  • schannel: decrypted data buffer: offset 0 length 102400
    < HTTP/1.1 400 Bad Request
    < Server: nginx
    < Date: Wed, 04 Dec 2019 21:19:37 GMT
    < Content-Type: application/json
    < Transfer-Encoding: chunked
    < Vary: Accept, Origin, Cookie
    < Allow: GET, POST, HEAD, OPTIONS
    <
    {“detail”: “JSON parse error - Expecting value: line 1 column 1 (char 0)”}* Connection #0 to host things.ubidots.com left intact

You can also use industrial.api.ubidots.com with the STEM version.

Make sure to use simple quotes for both double (") and single (') instead of the ones used in your request (“”) - (‘’).

If the error is still present after placing the right quotes, try putting the URL between double-quotes.

Best.
Maria H.

Greetings @CeJay, windows cmd does not support quoutes enclosures in terminal commands by default, so try to escape your double quotes before of making the request

curl -X POST -H "X-Auth-Token:BBFF-xxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type:application/json" -d "{\"value\": 59}" "https://things.ubidots.com/api/v1.6/devices/mqttdata/number/values" -vvv

All the best

Hi @jotathebest,

SUCCESS!!!

Have I missed this important information in your documentation? If I have sorry. If not, it is very important that this limitation of CMD is shared.

Thank you

1 Like

@CeJay I’m glad to hear it worked. :slight_smile:

To be honest, I’ve never used cmd to handle a request, and didn’t knew about that. Thanks @jotathebest