[SOLVED] Trying to send Non-GPS context with a variable

All,

I want to send non-GPS context with a variable and I believe the format would look like this:

{
    "Moisture": "{{Moisture}}",
    "Watering": {
        "value": "{{Watering}}",
        "context": "{{status}}"
    },
    "SoilTemp": "{{SoilTemp}}"
}
```

I have tested a JSON body for this structure and believe this is valid:
```
{"SoilTemp":"19","Watering":{"value": "0", "context": "Oops"},"Moisture":"516"}'
```
but when try to send using a curl command I get a response that I cannot figure out:
```
{"watering": [{"status_code": 400, "errors": {"context": ["'Oops' value must be a dict."]}}], "soiltemp": [{"status_code": 204}], "moisture": [{"status_code": 204}]}
```
I could not find a reference to error code 204 in the response code documentation and I could find no reference to ""'Oops' value must be a dict."". Can you please tell me what I am doing wrong.

Thank you for any help you might be able to provide.

Chip

Hello @chipmc,

As I can see on the requests you are building in a wrong way your context, the context is a key-value dictionary, so your payload should be something like this:

{"SoilTemp":"19","Watering":{"value": "0", "context": {"key1":"Oops"}},"Moisture":"516"}' https://things.ubidots.com/api/v1.6/devices/{DEVICE_LABEL}

So please try with this command:

curl -X POST -H 'Content-Type: application/json;' -H 'X-Auth-Token: {PUT_HERE_YOUR_TOKEN}' -d '{"SoilTemp":"19","Watering":{"value": "0", "context": {"key1":"Oops"}},"Moisture":"516"}' https://things.ubidots.com/api/v1.6/devices/{PUT_HERE_YOUR_DEVICE_LABEL}

Thanks so much for report the missing response code, we just updated the documentation, in a few minutes is gonna be available for the users.

All the best,
Maria C.

@mariahernandez,

Thank you for taking a look. I see what you are talking about now but the JSON you requested I put into the curl request is not passing muster.

Ubidots is giving me this response: {“detail”: “JSON parse error - Expecting ‘,’ delimiter: line 1 column 82 (char 81)”}

I have also tried the JSON payload in Rick K’s tester and I is not valid. Are we missing a comma? If so, where?

Thank you for your help,

Chip

@chipmc,

Sorry for that, I missed a quote into the command. Please can you try again? The command is already modified and tested.

Maria C.

@mariahernandez,

I was able to get it to work and was able to upload the datapoints, getting the 201 response code.

Please see the cross-linked post on Particle. Even though the data has been uploaded, it is not showing up under “context” for the Watering variable. How do I display this data?

Thanks, we are making progress!

Chip

@chipmc,

Regrettably I’m not able to reproduce your issue, is working properly on my side:

Keep in mind that with the payload provided, the only variable with context data is “Watering” so that is the one that you should check. Can you try again?

All the best,
Maria C.

@mariahernandez,

I tried again and it worked. Thank you!

Chip

1 Like