cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Entity key is not valid REST odata API

MichaelSchumach
7-Bedrock

Entity key is not valid REST odata API

We just upgrade our windchill environment to WC12.   I am trying to use the REST APIs for the first time and just trying using classic asp.

 

I have been successful using classic asp and doing a "GET" with my http request to retrieve a WTPart or WTDoc object.   I thought things were going well.

 

I wanted to try getting a BOM structure.  After a lot of reading, I read the GetBOM will be deprecated so I thought I would just try GetPartStructure.

 

I keep getting "404 error", "Entity key is not valid".   I read in article CS317238 i should be able to send an empty json string (i.e. {} ) .

 

Here is the sample code from my classic asp.

 

**** classic asp ****

set HttpReq = CreateObject("MSXML2.ServerXMLHTTP.6.0")
'
'get the WC token
'
HttpReq.Open "GET", "http://windschillserver/Windchill/servlet/odata/PTC/GetCSRFToken", False,"username","password"
HttpReq.setRequestHeader "Authorization","username:password"
HttpReq.setRequestHeader "Content-Type","application/json"
HttpReq.Send()

'Load JSON string
oJSON.loadJSON(HttpReq.ResponseText)
wcToken = oJSON.data("NonceValue")


'empty json - no NavigationCriteria to send
postData = "{}"

 

' GetPartStructure Rest API

HttpReq.Open "POST", "http://windchillserver/Windchill/servlet/odata/ProdMgmt/Parts('OR:wt.part.WTPart:5-023927')/PTC.ProdMgmt.GetPartStructure?$expand=Components($expand=Part($select=Name,Number),PartUse,Occurrence;$levels=max)" , False,"username","password"
HttpReq.setRequestHeader "Authorization","username:password"
HttpReq.setRequestHeader "Content-Type","application/json"
HttpReq.setRequestHeader "Content-Length", len(postData)
HttpReq.setRequestHeader "CSRF_NONCE",wcToken
HttpReq.Send postData

 

The response from the "HttpReq.Send postData" is the "entity key is not valid".

 

Any insight is greatly appreciated.

 

Thanks

Mike

2 REPLIES 2
rhart
14-Alexandrite
(To:MichaelSchumach)

Hi @MichaelSchumach 

I think the filter has to include max levels, if you try out getpartstructure in the api docs this filter is added to the url by default.

Thank you.   I had $levels=max in the POST url.   I took a closer look at 'OR:wt.part.WTPart:234318107'.   I was using an actual WTPart number like 5-023927 when, in fact, I should have been using the ida2a2 number for the WTPart.

 

Once I got the ida2a2 value from the WTPart table and used it, the GetPartStructure worked correctly.

 

Thanks for making me take a closer look.

 

Mike

Top Tags