Monday 17 June 2019

Create UNIX timestamp for ArcGIS Server Feature REST API

When you feed or update datetime column in ArcGIS REST API the current date and time has to be in UNIX epoch milliseconds.

In Python this is the easiest way to do:

The *1000 is required to get the milliseconds from the seconds. Obviously this way is only accurate to the second...if you want to gain more precision you should perhasp go with this:
With this methodology you will not loose the milliseconds due to integer rounding.

Friday 14 June 2019

Cannot convert a value of type \'java.lang.String\' to \'TIMESTAMP\'

The ArcGIS REST API just needs an epoch time bigint - so convert it to numbers.

To check the values this site works:

How to prepare JSON payload for ArcGIS Feature Service using Python

There you have it - this is just a dump from my code - purely to remind myself...

What it does it creates a point array then using Python it puts this payload to an ArcGIS Feature Service.

ptemp = {}
... print type(ptemp)
... ptemp["attributes"]={}
... ptemp["attributes"]["objectid"]=1
... ptemp["attributes"]["s"]=223
... ptemp["attributes"]["a"]="a val"
... ptemp["attributes"]["n"]="n val"
... ptemp["attributes"]["b"]=123
... ptemp["attributes"]["p"]="p val"
... ptemp["attributes"]["g1"]=11
... ptemp["attributes"]["g2"]=22
... ptemp["attributes"]["g3"]=33
... ptemp["attributes"]["g4"]=44
... ptemp["attributes"]["g5"]=55
... ptemp["geometry"]={}
... ptemp["geometry"]["x"]=152.95359856272353
... ptemp["geometry"]["y"]=-23.461733290059232
... ptemp["geometry"]["spatialReference"]={"wkid" : 4326}

So we created the ptemp dictionary object with point parameters.

>>> url = config["serviceurl"]+"/0/addFeatures?token={}&f=pjson"
... token = getToken("uname", "password")
... url = url.format(token)

Now we acquired the token and added to url.

>>> pptemp = []
>>> pptemp.append(ptemp)

Now we just put the dictionary to a list - this needed for the ArcGIS Feature Service.

pt = urllib.quote_plus(json.dumps(pptemp))

Now we created an encoded payload from json string.
...and finally we send all of these to the ArcGIS Feature Service in a POST request:

>>> request.add_header("Content-Type",'application/x-www-form-urlencoded')
>>> request = urllib2.Request(url, data=st)
>>> connection =
>>> connection.readlines()