Pulling inventory through REST API v.1 via PartSvc

Hi awesome people,

I am trying to pull inventory information from Epicor via REST API v.1 and using Erp.BO.PartSvc. I have a filter(basically ItemMask) to get a particular set of parts …/api/v1/Erp.BO.PartSvc/Parts?$filter=ItemMask and then for each part I want to get some Warehouse data like QtyOnHand, DemandQty and maybe something else, but those two for sure. So for that, I think I could use …/api/v1/Erp.BO.PartSvc/PartWhses as it has all the necessary fields I need. However, I do not see the way how do I limit returned records by the number of warehouses. I tried to build different filters from the swagger page just to play and see if can get something nice but was not able to achieve what I need.

Example:

I have part A in the warehouses 1,2,3,4 and 5 but I am only interested in Inventory for part A in warehouses 1,3 and 5. Is it possible to achieve this if using /PartWhses entity?

I looked at other BO’s and entities but could not find a suitable one for my needs. Let me know if you need any additional info to be posted/added.

Thank you,

Alex

How about using the [GET] /PartWhses({Company},{PartNum},{Plant},{WarehouseCode}) service for each warehouse you want to retrieve?

How are you trying to limit the records?

Hey Josh,

I wanted to eliminate number of requests I need to make as well as using Plant in my case won’t be possible. Let’s say I know only PartNum, Company and a bunch of WarehouseCodes (something like comma separated list of WarehouseCodes). For now I am looking for a way to limit it by embedding list of warehouses into a filter but, I guess it won’t work for multiple warehouses.

Have you tried to create a BAQ and use the API to pull exactly the data you need?

2 Likes

Looks like using an “or” on the main GET /PartWhses filter would work. The following filter would return only 1, 3, and 5 warehouse codes.

/Erp.BO.PartSvc/PartWhses?$filter=WarehouseCode%20eq%20’1’%20or%20WarehouseCode%20eq%20’3’%20or%20WarehouseCode%20eq%20’5’

Hi Lena,

I am not sure how to do that kind of BAQ. I have more programming background than Epicor. I can solve this problem by grabbing all the warehouses and then filter them but I do not want to load the whole bunch of not required parts into a memory.

You should be using PartNum in your filter as well. Using your example plus PartNum did not work for me. I guess something like this:

/PartWhses?$filter=PartNum%20eq%20’TESTPart’%20and%20WarehouseCode%20eq%20’TEST’%20or%20WarehouseCode%20eq%20’MAIN’

is not a valid OData request.

I just added a PartNum now and it still executed successfully…

PartNum eq ‘000-LAPTOP’ and WarehouseCode eq ‘Main’ or WarehouseCode eq ‘Fastenal’

The problem looks to be your apostrophes. Try copying your filter to Notepad and replace all the apostrophes with new ones.

I am so sorry Josh. When I said it did not work for me I meant that I received first 100 parts but not the part I need with only two warehouses. So yes, it works but gives undesired output.

Another possible option is to utilize the BO object:

Erp.Contracts.BO.PartWhseSearch.dll

This method would possibly work with the ability to specify the page size.

public PartWhseSearchDataSet GetRows(string whereClausePartWhseSearch, int pageSize, int absolutePage, out bool morePages);

The problem with this approach is that I need to get total number of part records in the system which might take significant amount of time(depends on how many parts you have) in order to use it for pageSize.

I tried your suggestion but that still gave me first 100 parts back

{
"whereClausePartWhseSearch" : "PartNum='TESTPart' and WarehouseCode='TEST' or WarehouseCode='MAIN'",
"pageSize" : 100,
"absolutePage" : 0
}

I guess there is no way to achieve what I want in completely efficient way. BAQ might help but, I am doubting I will go that way.

bool morePages;

If you called the BO method like this, if there are more results, morePages would return true. I would wrap this inside a loop and then set the absolutePage +=100 each time morePages returns true. This would essentially page through all the results.

Something like this:

        Ice.Core.Session session = new Ice.Core.Session(userID, password, Ice.Core.Session.LicenseType.EnterpriseProcessing, {app's location}.sysconfig);
        Erp.Proxy.BO.PartWhseSearchImpl WhseSearch = Ice.Lib.Framework.WCFServiceSupport.CreateImpl<Erp.Proxy.BO.PartWhseSearchImpl>(session, Erp.Proxy.BO.PartWhseSearchImpl.UriPath);

        bool morePages;
        int absPage = 1;

        do
        {
            var recs = WhseSearch.GetRows("WarehouseCode eq 'Main' or WarehouseCode eq 'Fastenal'", 100, absPage, out morePages);
            absPage += 100;
        } while (morePages);

If you pass in the Db object from Epicor, you can search them this way:

    public static List<Erp.Tablesets.PartWhseSearchTableset> WhseRecords(Erp.ErpContext dbContext, int partNum)
    {
        //This is referencing Erp.Contracts.BO.PartWhseSearch.dll
        Erp.Contracts.PartWhseSearchSvcContract PartWhseSearchSvc = Ice.Assemblies.ServiceRenderer.GetService<PartWhseSearchSvcContract>(dbContext);

        List<Erp.Tablesets.PartWhseSearchTableset> results = new List<Erp.Tablesets.PartWhseSearchTableset>();
        bool morePages;
        int absPage = 1;

        do
        {
            Erp.Tablesets.PartWhseSearchTableset recs = PartWhseSearchSvc.GetRows("WarehouseCode eq 'Main' or WarehouseCode eq 'Fastenal'", 100, absPage, out morePages);
            results.Insert(0, recs);
            absPage += 100;
        } while (morePages);

        return results;
    }

All these answers seem complicated to me. Wouldn’t this be a simple single table BAQ on the PartWhse table that you can then set either a fixed filter on the BAQ, or a Parameter if you want to vary the filters from outside of epicor?

1 Like

Hi Josh,

Yeah, I know how to loop through all pages I’ve done that through OData as well but again, it will give me parts that I do not need. The main problem here I think is that it should be done through API only and nobody will go for BAQ but, I guess that’s the only way to do it efficiently though. We will see. Thanks all for your awesome help. I will keep BAQ in mind.

Alex