Why are you using POST
instead of PUT
? Documentation clearly says that you should be using PUT
method.
Good Day Anton
Please see following Python Code and see if you can see why it returns not JSON Object on PUT:
import requests
import json
URL1 = "http://domain:8082/api/devices"
URL2 = "http://domain.co.za:8082/api/devices/3"
USER = 'admin'
PASSWORD = 'password'
DEVICE = '6889910284'
PARAMS = {'uniqueId':DEVICE}
HEADERS = {"Content-Type": "application/json"}
response1 = requests.get(URL1, auth=(USER, PASSWORD), headers=HEADERS, params = PARAMS)
datax = response1.json()
print(datax)
DATA = {
'attributes': {},
'category': datax[0]["category"],
'contact': datax[0]["contact"],
'disabled': datax[0]["disabled"],
'geofenceIds':{},
'groupId': datax[0]["groupId"],
'id': datax[0]["id"],
'lastUpdate': datax[0]["lastUpdate"],
'model': datax[0]["model"],
'name': datax[0]["name"],
'phone': datax[0]["phone"],
'positionId': datax[0]["positionId"],
'status': datax[0]["status"],
'uniqueId': datax[0]["uniqueId"]
}
response2 = requests.put(URL2, auth=(USER, PASSWORD), headers=HEADERS, data=DATA)
datay = response2.json()
print(datay)
Thank You
Albertus Geyser
Good Day Anton
I did check what it return and implemented what it could be:
import requests import json url = "http://domain.co.za:8082/api/devices/1" user = 'admin' password = 'password' data = { "attributes":{}, "category":"default", "contact":"", "disabled":"true", "geofenceIds":{}, "groupId":1, "id":1, "lastUpdate":"2018-05-17T19:48:17+02:00", "model":"Huawei", "name": "Huawei", "phone":"+27877778523", "positionId":21926, "status":"online", "uniqueId":671996 } headers = {"Content-Type": "application/json"} response = requests.post(url, auth=(user, password), headers=headers, data=data) print(response.text)
But this give me an error:
Thank You
Albertus Geyser