0

I am trying to call a Windchill Odata rest service. THE HTTP GET method works fine, but it is not working as expected when making a POST request. I am also not sure how to pass the required parameter to the URL. Any suggestions will help a lot.

URL that I am trying to call

http://Hostname/Windchill/servlet/odata/v3/ProdMgmt/Parts('OR:wt.part.WTPart:123456')/PTC.ProdMgmt.GetPartStructure?$expand=Components($select=PartName,PartNumber;$expand=PartUse($select=FindNumber,LineNumber,Quantity,Unit);$levels=1)

Parameter that need to be passed to the URL is ('OR:wt.part.WTPart:123456'). I am doing this in C# .NET.

My C# code

using (var client = new HttpClient())
 {
  client.DefaultRequestHeaders.Accept.Add(new 
 MediaTypeWithQualityHeaderValue("application/json"));

  var byteArray = Encoding.ASCII.GetBytes("abc:defg!");

  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

  client.DefaultRequestHeaders.Add("CSRF_NONCE", a.NonceValue);

   var message = await client.PostAsync("hostname/Windchill/servlet/odata/v3/ProdMgmt/Parts('OR:wt.part.WTPart:123456')/PTC.ProdMgmt.GetPartStructure?$expand=Components($select=PartName,PartNumber;$expand=PartUse($select=FindNumber,LineNumber,Quantity,Unit);$levels=1)", null);
  }

Any example or sample code is much appreciated.

shasi
  • 61
  • 1
  • 1
  • 4
  • 1
    Where is your C# code? – maccettura Jun 15 '21 at 19:01
  • Hi I have added the C# code to my question. Thank you for checking my question. Any help is appreciated – shasi Jun 15 '21 at 19:14
  • How specifically does the code fail? How have you confirmed that it's failing here and not on the server? – David Jun 15 '21 at 19:24
  • When you POST data, you will usually need to put the data in the HTTP body, not in the querystring as you are doing. See [this answer](https://stackoverflow.com/questions/20005355/how-to-post-data-using-httpclient) – John Wu Jun 15 '21 at 19:26
  • duplicate https://stackoverflow.com/questions/4015324/how-to-make-an-http-post-web-request – git test Jun 15 '21 at 19:30
  • @JohnWu I tried it the below way but getting Status Code: 406 - 'Not Acceptable' error var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair("PartId", "OR:wt.part.WTPart:4143527554") }); HttpResponseMessage message = await client.PostAsync("v3/ProdMgmt/Parts('{PartId}')/PTC.ProdMgmt.GetPartStructure", formContent); – shasi Jun 15 '21 at 20:04
  • 2
    You will need to talk to the people who run that service, or read their documentation. Sounds like you aren't sending data the way they expect, but there is no way I can tell you what they are expecting. – John Wu Jun 15 '21 at 20:12

0 Answers0