AnsweredAssumed Answered

PI Web API Batch Post Help (Python)

Question asked by aman720 on Nov 18, 2019
Latest reply on Nov 19, 2019 by aman720

Hello All,

 

I am using Python to try and write multiple values to an attribute using the PI Web API. My initial script loops through each timestamp and value, and posts them individually. This takes a long time to run as there is a lot of data to write, so I was exploring to find a way to make a single post request with all the values and timestamps I need. I did some research and experimented with my script, but to no success. I keep getting the 400 status code. Here is the basic script I am running. For simplicity's sake, I am only trying to post twice.

 

 

 

import requests

url = https://myserverhere/piwebapi/streams/webid/value
body = {
"Timestamp": ["11/14/2019 13:18:47" ,"11/18/2019 4:16:00"],

"Value": [1000.5, -1000.5]
}


r = requests.post(url, json=body, auth= user/pw, headers = {'Content-Type': 'application/json', 'Accept':'application/json'} )

print(r.status_code)
print(r.url)

 

From what I have read online, it seems like I may be formatting the body incorrectly? However, I have tried multiple configurations of the body. I think the API configuration is set up correctly as well. Any help/guidance would be greatly appreciated.

Outcomes