AnsweredAssumed Answered

EncodeURI incompatible with PI Web API?

Question asked by Roger Palmen on Jan 11, 2018
Latest reply on Jan 12, 2018 by Roger Palmen

Hi all,


Did a surprising find. I used to use encodeURI for the individual calls going into the PI Web API:

var getDataStreamURL = encodeURI(PIWebAPIURL + "streams/" + datastream.WebID + "/interpolatedattimes?time={0}");


But the replacement of the {0} by %7B0%7D" caused the following error to return for the individual call:

'{0}' is not a valid timestamp.


Just bypassing the encodeURI works just fine:

var getDataStreamURL = PIWebAPIURL + "streams/" + datastream.WebID + "/interpolatedattimes?time={0}";


For additional reference, the call is eventually made by:

                        //Add to batch call
                        batchRequest[index+1] = {
                            'Method': 'GET',
                            'RequestTemplate': { 'Resource': getDataStreamURL },
                            'ParentIDs': ['0'], //link to first batch call
                            'Parameters': ['$.0.Content.Items[*].Timestamp'] //map to timestamp of first batch call


            var batchURL = JSON.stringify(batchRequest)
            var promise = $ + 'batch', batchURL, { withCredentials: true });


Any suggestions how i need to see this?