AnsweredAssumed Answered

Traversing and querying weak-referenced elements using the PI Web API

Question asked by AbelHeinsbroek on Feb 25, 2019
Latest reply on Feb 26, 2019 by rschmitz

Hi All,

 

I'm struggling with the following. Lets imagine I have a collection of assets organized like this that I want to traverse using the PI Web API:

 

 

I can query the web-api for all underlying elements (GetElements) of "Asset Collection 1", which results in:

 

{
"Items": [
{
"WebId": "F1Em7_EqmZ0RlE-cAZ0KsFBMtAWGEhvfk46RGD4QBQVgF0AgU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVFNcQQ",
"Path": "\\\\sr-16642\\Abel Heinsbroek - dev\\API Tests\\Assets\\A"
},
{
"WebId": "F1Em7_EqmZ0RlE-cAZ0KsFBMtAfNDKaPo46RGD4QBQVgF0AgU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVFNcQg",
"Path": "\\\\sr-16642\\Abel Heinsbroek - dev\\API Tests\\Assets\\B"
}
]
}

 

As you can see the returned Paths point back to the location of the original element. Is there any way to have the Web API return the paths relative to the weak-referenced parent element instead?

 

An additional problem is that the WebID is also encoded for the path to the original element, which causes problems with client side generated WebIDs.

For example, I want to retrieve the value of attribute "\\sr-16642\Abel Heinsbroek - dev\API Tests\Asset Collection 1\A|Test", which translates into client generated WebID

P1AbEU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVCBDT0xMRUNUSU9OIDFcQXxURVNU

 

I often automatically group together multiple attribute value requests using Streamsets / AdHocValues, resulting into the following response:

 

{
"Links": {},
"Items": [
{
"WebId": "P1AbEU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVFNcQXxURVNU",
"Name": "Test",
"Path": "\\\\sr-16642\\Abel Heinsbroek - dev\\API Tests\\Assets\\A|Test",
"Links": {
"Source": "https://piwebapi/piwebapi/attributes/P1AbEU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVFNcQXxURVNU"
},
"Value": {
"Timestamp": "1970-01-01T00:00:00Z",
"Value": 123.0,
"UnitsAbbreviation": "",
"Good": true,
"Questionable": false,
"Substituted": false
}
}
]
}

 

As you can see the WebID in the response is different from the one in the request as it again maps to the original element, and not the weak-referenced one.

 

Request : P1AbEU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVCBDT0xMRUNUSU9OIDFcQXxURVNU
Response: P1AbEU1ItMTY2NDJcQUJFTCBIRUlOU0JST0VLIC0gREVWXEFQSSBURVNUU1xBU1NFVFNcQXxURVNU

 

This makes response handling a lot more cumbersome than it needs to be.

 

Do you guys know a good workaround for this problem, or if its possible to have the WebAPI follow weak-referenced paths?

 

Thanks!

 

Abel

Outcomes