cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating DATETIME Property Using the REST API

Highlighted
Newbie

Updating DATETIME Property Using the REST API

Hi everyone.

I am trying to update a Thing property of type "DATETIME" with a historical time through the REST API (I have a CSV file with datetime values that I want to sequentially update the Thing's properties with, but for now, I just want to update the property once).

I am currently using the Requests package in Python to communicate with the REST API, although I have previously tried this using the HTTPie extension in the Windows Command Prompt and had no luck no matter how I formatted the datetime value.

I have tried updating the Thing property with an example time by formatting the new value as a string in the same format that is returned in Python when you use a GET request for a datetime property's value (script below), but I wasn't successful.  I keep getting the error "Unable To Convert From java.lang.String to DATETIME"

Does anyone happen to know how I can update the DATETIME property using Requests in Python (or any other http requests language, really.  Anything is helpful)?

Thank you!

import requests

headers = {'appkey':'<appkey_code>', 'Content-Type':'application/json'}

payload = {'MonsterMash_time':'2017-07-03 17:21:00'}

r = requests.put('http://<SERVER>/Thingworx/Things/<ThingName>/Properties/MonsterMash_time', json=payload, headers=headers)

1 REPLY 1

Re: Updating DATETIME Property Using the REST API

So, I had been attempting to update a DATETIME property for days, and within seconds of posting this question, I found something else, tried it, and it worked.  Here's what I did for anyone who comes across the same problem:

I used the ISO 8601 format (YYYY-MM-DDTHH:MMSmiley FrustratedS.mmmmmm) which I had just read is the standard format for date and time.  My script now looks like this:

-------------------------------------------

import requests

headers = {'appkey':'<appkey_code>', 'Content-Type':'application/json', 'Accept':'text/csv'}

payload = {'MonsterMash_time':'2017-07-03T17:21:00.003000'}

r = requests.put('http://<SERVER>/Thingworx/Things/<ThingName>/Properties/MonsterMash_time', json=payload, headers=headers)

------------------------------------------

The only real different is a "T" instead of a space and a few zeros.