Hi, I need to call api to retrieve some transactions details from 3rd party application into acumatica erp. For testing, I used below code in my own customization project. This is a POST request and url is also defined there.
public virtual async Task<IEnumerable> InsertSelectedLines(PXAdapter adapter)
{
foreach (PXResult<SOLine, SOOrder> result in POrdersView.Select())
{
if (lineExt.Selected1 == true)
{
APProformaItemList toBeInserted = new APProformaItemList();
toBeInserted.Ponbr = order.OrderNbr;
toBeInserted.LineNbr = lineNbr++;
var url = String.Format("https://sandbox.corporate-
api.hsbc.com/mock/v2/transactions");
HttpClient client= new HttpClient(); //added reference
client.DefaultRequestHeaders.Add("ContentType","
application/json");
client.DefaultRequestHeaders.Add("x-report-type", "JSON");
string data = "test=something";
//var stringContent = new StringContent(json, Encoding.UTF8,
"application/json");
StringContent queryString = new StringContent(data);
HttpResponseMessage response = await client.PostAsync(url,
queryString);
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.OK)
{
toBeInserted.Description = "test if";
}
else
{
//throw new Exception(content);
toBeInserted.Description = " else";
}
}
}
}
return adapter.Get();
Above code defined inside a method which is used to add values from smart panel to custom screen details level. I just need to test whether this is working or not, that’s why I’m assigning some testing values to description field. But the time I adding values from the screen, I’m getting the error-
“Unable to cast object of type 'System.Threading.Tasks.Task`1[System.Collections.IEnumerable]' to type 'System.Collections.IEnumerable'”
Can someone help me to find a solution to this or provide me the guidance to get this done?
Thank you.