Hi,
I have a third party rest api to get bank details.
When calling the API it response is json format.
When I click the ADD Order Button I need to add response statusDesc with sales order descirption field.
public PXAction<SOOrder> MyAction;
[PXUIField(DisplayName = "ADD ORDER", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton(CommitChanges = true)]
public virtual IEnumerable myAction(PXAdapter adapter)
{
var URL = "https://sandbox.corporate-api.hsbc.com/mock/v2/transactions";
var httpRequest = (HttpWebRequest)WebRequest.Create(URL);
httpRequest.Method = "POST";
httpRequest.ContentLength = 0;
//IRestResponse response = client.Execute(httpRequest);
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
//string responseBody = httpResponse.Content.ReadAsStringAsync();
SOOrder order = Base.Document.Current;
//order.OrderDesc = httpResponse.ContentType.ToString();
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = httpResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(ReceiveStream, encode);
Console.WriteLine("\nResponse stream received");
Char[] read = new Char[2560000];
// Read 256 charcters at a time.
int count = readStream.Read(read, 0, 2560000);
String str = new String(read, 0, count);
var myDetails = JsonConvert.DeserializeObject < MyDetail > (str);
order.OrderDesc = myDetails.statusDesc;
return adapter.Get();
}
But,When clicking the button below error is shown.
Best answer by jinin
View original