I am working on some utilities to automate some processes. I am wanting to return a list of Companies from Epicor, so I figured I would use the Erp.BO.CompanySvc/GetList method. I can get the data back in the ResponseData, but I have not figured out how to access it. The examples I saw in the forums showed a couple of different methods, but none have yet worked. I am using the EpicorRestAPI nuget package also.
var response = EpicorRest.BoGet("Erp.BO.CompanySvc", "GetList", dic, callContext);
if (!response.IsErrorResponse)
{
foreach (var item in response.ResponseData)
{
tempList.Add(item.CompanyList.Company); // I have tried a bunch of different permutations of this and not gotten any of them to work
}
}
The data being returned looks right, I am just not sure how to parse it out.
I am using v2. I know there was a documentation page with some examples, but I do not remember where they were located.
I had used this structure below, but it did not return anything when I tried it.
//The code above returns an EpicorResponseObject (response) below are some ways to use it
// Allows you get an individual property from your response using the dynamic object
response.ResponseData.value[0].Company
It gave a null error:
‘Cannot perform runtime binding on a null reference’
What I found after further research, is the OData methods will work and give data like the example, but not the custom methods. I’ll get into those next I think. Below is what I came up with for a working code segment
CallContextHeader callContext = new CallContextHeader();
var response = EpicorRest.BoGet("Erp.BO.CompanySvc", "Companies", dic, callContext);
if (!response.IsErrorResponse)
{
var company = response.ResponseData.value[0].Company1;
var limit = response.ResponseData.value.Count;
for (int i = 0; i < limit; i++)
{
tempList.Add(response.ResponseData.value[i].Company1.ToString());
}
//tempList.Add(item.value[0].Company1);
}