Ubidots Community

[SOLVED] Http post multiple variables and values retrospectively with a timestamp

Hi, I’m trying to post multiple variables with a retrospective absolute timestamp, using HTTP post
I saw a previous topic about multiple values and putting it together with another answer, I came up with this:
Here is my data - is this supported? is the syntax correct? I am using the python ‘requests’ library to do this, I get a 400 error code.

[{‘Ambient_Light’: {‘value’: 2.29, ‘timestamp’: 1580514430806}, ‘Dawn2Dusk’: {‘value’: -13, ‘timestamp’: 1580514430806}, ‘Drynessmap’: {‘value’: ‘11111111’, ‘timestamp’: 1580514430806}, ‘High2Low’: {‘value’: 33, ‘timestamp’: 1580514430806}, ‘Humidity_In’: {‘value’: 52.6, ‘timestamp’: 1580514430806}, ‘Humidity_Out’: {‘value’: 57.3, ‘timestamp’: 1580514430806}, ‘Levelmap’: {‘value’: ‘10101111’, ‘timestamp’: 1580514430806}, ‘LightTotal’: {‘value’: 338, ‘timestamp’: 1580514430806}, ‘Openingmap’: {‘value’: ‘10010110’, ‘timestamp’: 1580514430806}, ‘Pressure_Out’: {‘value’: 1030.4, ‘timestamp’: 1580514430806}, ‘Temperature_1’: {‘value’: 23.5, ‘timestamp’: 1580514430806}, ‘Temperature_2’: {‘value’: 23.5, ‘timestamp’: 1580514430806}, ‘Temperature_3’: {‘value’: 23.7, ‘timestamp’: 1580514430806}, ‘Temperature_4’: {‘value’: 26.0, ‘timestamp’: 1580514430806}, ‘Temperature_5’: {‘value’: 24.5, ‘timestamp’: 1580514430806}, ‘Temperature_6’: {‘value’: 23.0, ‘timestamp’: 1580514430806}, ‘Temperature_In’: {‘value’: 24.2, ‘timestamp’: 1580514430806}, ‘Temperature_Out’: {‘value’: 23.1, ‘timestamp’: 1580514430806}, ‘Wind_Direction’: {‘value’: 69.0, ‘timestamp’: 1580514430806}}]

For info, I am able to post this the below data in real time, and it works fine
{‘Temperature_3’: 23.7, ‘Temperature_Out’: 23.1, ‘Temperature_5’: 24.5, ‘Temperature_4’: 26.0, ‘High2Low’: 33, ‘Openingmap’: ‘10010110’, ‘Wind_Direction’: 69.0, ‘Temperature_1’: 23.5, ‘Dawn2Dusk’: -13, ‘Ambient_Light’: 2.29, ‘Temperature_In’: 24.2, ‘Pressure_Out’: 1030.4, ‘Humidity_Out’: 57.3, ‘Humidity_In’: 52.6, ‘LightTotal’: 338, ‘Temperature_6’: 23.0, ‘Drynessmap’: ‘11111111’, ‘Temperature_2’: 23.5, ‘Levelmap’: ‘10101111’}

SOLVED!
just don’t put the dictionary in a list - like this:
{‘Ambient_Light’: {‘value’: 2.29, ‘timestamp’: 1580514430806}, ‘Dawn2Dusk’: {‘value’: -13, ‘timestamp’: 1580514430806}, ‘Drynessmap’: {‘value’: ‘11111111’, ‘timestamp’: 1580514430806}, ‘High2Low’: {‘value’: 33, ‘timestamp’: 1580514430806}, ‘Humidity_In’: {‘value’: 52.6, ‘timestamp’: 1580514430806}, ‘Humidity_Out’: {‘value’: 57.3, ‘timestamp’: 1580514430806}, ‘Levelmap’: {‘value’: ‘10101111’, ‘timestamp’: 1580514430806}, ‘LightTotal’: {‘value’: 338, ‘timestamp’: 1580514430806}, ‘Openingmap’: {‘value’: ‘10010110’, ‘timestamp’: 1580514430806}, ‘Pressure_Out’: {‘value’: 1030.4, ‘timestamp’: 1580514430806}, ‘Temperature_1’: {‘value’: 23.5, ‘timestamp’: 1580514430806}, ‘Temperature_2’: {‘value’: 23.5, ‘timestamp’: 1580514430806}, ‘Temperature_3’: {‘value’: 23.7, ‘timestamp’: 1580514430806}, ‘Temperature_4’: {‘value’: 26.0, ‘timestamp’: 1580514430806}, ‘Temperature_5’: {‘value’: 24.5, ‘timestamp’: 1580514430806}, ‘Temperature_6’: {‘value’: 23.0, ‘timestamp’: 1580514430806}, ‘Temperature_In’: {‘value’: 24.2, ‘timestamp’: 1580514430806}, ‘Temperature_Out’: {‘value’: 23.1, ‘timestamp’: 1580514430806}, ‘Wind_Direction’: {‘value’: 69.0, ‘timestamp’: 1580514430806}}

Hello @tonyg,

I’m glad you were able to work it out. If you have any additional questions, remember that we are here to help you. :smiley:

Cheers,
Maria H.

I looked at this again following a local network failure (the very reason for this issue), and while the syntax was OK and the post succeeded with a <400 result, the variables actually did not update in ubidots - the values were not updated - there was no retrospective ‘dot’.
I had to go to another method of posting each value separately, and I had to look up the variable ID from its name to do this (there does not seem to be a method to facilitate this action).
This is a bit of a pain - what’s wrong with posting the above JSON? Could this be retested?

Hi @tonyg.

I hope all is well,

400 response correspond to a bad request, due an invalid JSON. Having that in mind you should correct your JSON payload as below:

{"Ambient_Light": {"value": 2.29, "timestamp": 1580514430806}, "Dawn2Dusk": {"value": -13, "timestamp": 1580514430806}, "Drynessmap": {"value": 11111111, "timestamp": 1580514430806}, "High2Low": {"value": 33, "timestamp": 1580514430806}, "Humidity_In": {"value": 52.6, "timestamp": 1580514430806}, "Humidity_Out": {"value": 57.3, "timestamp": 1580514430806}, "Levelmap": {"value": 10101111, "timestamp": 1580514430806}, "LightTotal": {"value": 338, "timestamp": 1580514430806}, "Openingmap": {"value": 10010110, "timestamp": 1580514430806}, "Pressure_Out": {"value": 1030.4, "timestamp": 1580514430806}, "Temperature_1": {"value": 23.5, "timestamp": 1580514430806}, "Temperature_2": {"value": 23.5, "timestamp": 1580514430806}, "Temperature_3": {"value": 23.7, "timestamp": 1580514430806}, "Temperature_4": {"value": 26.0, "timestamp": 1580514430806}, "Temperature_5": {"value": 24.5, "timestamp": 1580514430806}, "Temperature_6": {"value": 23.0, "timestamp": 1580514430806}, "Temperature_In": {"value": 24.2, "timestamp": 1580514430806}, "Temperature_Out": {"value": 23.1, "timestamp": 1580514430806}, "Wind_Direction": {"value": 69.0, "timestamp": 1580514430806}}

Additionally, please keep in mind that there’s a package size limit per request, which is 10kB or what is the same 10k characters. STEM users has a throttling limit of 30 dots per minute across all devices, and up to 4,000 dots per day .

All the best,
-Isabel

Thank you Isabel, so the difference between my Jason and yours is only the use of double quotes instead of single ones? Of have i missed another difference?
Can I also clarify I did not get a 400 response, but a lower than 400, meaning I think a good request. What actually happened in ubidots is that there were a number of equal dots created with the same value all time stamped with the current time plus some milliseconds.

Many thanks for your reply.

Hi @tonyg,

Mainly yes, I modified the JSON for double quotes but also delete some values that have quotes unneeded. Are you still presenting this behavior? If yes, can you please send me an screenshot of the problem?

Best,
-Isabel