Hi all,
this is the first time for me to using REST API . i'm start learning from SWAGGER, everything in swagger page working good. i can get value or put value in to the data point via Xid, it easy to use and power full. in figure below show for detail of PUT point-values/{Xid} had success.
after that i'm try to get and put value from point-values via Python code. The Cookie issue for request header are solve in help forum. i'm trying several time. so it working only for request get() value, but when using request put() i receive response of request status code is 403. maybe the code is not correct, i don't know how to declare the body content of payload. i wish someone help. i have the code in below
import requests
import json
## STEP [1]-------------------------------------------------------------------------
s = requests.Session()
s.headers.update({'Cookie':'MANGO8080=1mk606ffnwaxywwielclj4ck2; XSRF-TOKEN=dc1d54de-fab1-4405-8ccb-ea677aadf7ca','X-Xsrf-Token':'dc1d54de-fab1-4405-8ccb-ea677aadf7ca','Accept': 'application/json', 'Content-Length': '39', 'Accept-Encoding': 'gzip', 'Content-Type': 'application/json;charset=UTF-8'});
url3 = 'http://localhost:8080/rest/v2/login'
js = {'username': "admin", 'password': "admin"}
r = s.post(url3, data=json.dumps(js));
s.headers.update({'Cookie' : r.headers['Set-Cookie']})
del s.headers["Content-Length"]
del s.headers["Content-Type"]
del s.headers["Cookie"]
del s.headers["X-Xsrf-Token"]
## STEP [2]-- get device name -----------------------------------------------------------------------
r = s.get('http://localhost:8080/rest/v1/device-names', timeout=5);
print ('\n device name')
print( r.text)
## STEP [3]-- get Point value by {Xid} ---------------------------------------------------------------
r = s.get('http://localhost:8080/rest/v1/point-values/DP_6bcc108f-faa1-47fb-b310-1acc8b047fd2/latest?useRendered=false&unitConversion=false&limit=1&useCache=true', timeout=5);
print ('\n Point value')
print( r.text)
## STEP [4]------ put Point value by {Xid} ---------------------------------------------------------
dd = {'dataType': "BINARY", 'value': "true", 'timestamp': 0, 'annotation': "rest by TST 12"}
url2 = 'http://localhost:8080/rest/v1/point-values/DP_6bcc108f-faa1-47fb-b310-1acc8b047fd2?unitConversion=false'
r = s.put(url2, data=json.dumps(dd));
print ('\n post')
print(r)
print( r.text)
the request status code in step 1 - 3 is <200> but step 4 is <403> please help !
Best regard.