Rest User Application Error - Help Needed Part 2

A few months ago I made a C# program that could tap into rest using Rest Epicor Nuget. See the previous post where the epiusers crew helped me build it here:

The program worked fine until recently when I started getting the following error again:

I was able to get around this once by changing the user credentials. But now the issue persists. I am unsure if it is timing out before it is receiving data or what. Any clues are appreciated.

This is a generic C#/.Net error that simply states:

“Hey, you’re accessing a variable that hasn’t been assigned anything and you’re not testing for that condition. You better fix it”

More often than not, a record is not found the the code assumes that can’t happen but it can be other reasons too. Go through your code and do some null checking to put guard rails around unexpected missing data.


Could you give me an example of how to null check?


I tried using the var results != null but this behavior causes the same error before the code runs. The current Null error happens after the 1:40 minute mark of the program. That is why I believe that it is a time out thing. How do I tell the code not to time out?

Are you seeing a timeout error in your logs? Are you using Try/Catch blocks around your code and handling error handling explicitly?

If you’re timing out, then you need to fix the query you’re running. Make sure you’re using keys properly in links. Do your most restrictive query first to a list then use the list to add extra data as needed.

Trying to troubleshoot this in PostMan to see if I can get it to go through there. What do we enter for the key, {username}:{password} in base64?

You concatenate the username + ‘:’ + password then base64 encode it. See example here for the idea. .Net has the encoder as well.


I was adding in the {} on either side of the concatenation, my bad. Also, does the key have to have a type associated with it, or do I just add it to the back of the request URL?

In Postman, it does it for you in the Authorization Tab:

In your code, it goes in the Authorization line of the http headers:


I just realized I was trying to pass credentials in the Params section instead of the authorization section…happy second Monday?

I can get PostMan to Pull that query pretty fast without any issues, which means that the dynamic get section of code seems to be the problem. Are there better ways of getting the data compared to the following:


Seriously though, thanks for all the help Mark!

Was the nuget package updated? (Maybe a bug in DynamicGet)
Was epicor updated just before the error started? (A bug in Epicor, if possible enable server logging and see if the errors appear there)
Can you try a system baq or a new but simpler baq instead of APOTool2? (Maybe something specific to this BAQ causes the error?

If nothing works maybe @josecgomez has more ideas :stuck_out_tongue:


I updated the nuget package earlier, should be up to date. We haven’t had an upgrade recently, at least not since this last worked. As for trying another baq it exits with code 0… not sure what that means. Thanks for the insight!

As far as performance goes, I’ll leave that to @josecgomez and @jgiese.wci as they are the authors behind that library and know how to make it sing.

Quick note about Basic Authentication. As you see, the username and password is encoded but not one way. This is why Epicor requires us to have certs protecting the traffic. Any persistent threat on your network will be looking for Basic Auth headers going by to pick out credentials and grab any API-Keys. Eventually, you’ll want to get to token access. It’s documented in the REST guide but I’m pretty sure the NuGet package does it too.

What version of the nugget are you using?
There is a RestLog property that you can look at that can tell you more info
Anything there in the RestLog property?

This is the first I’m hearing of a token option. I will have to dig into that. Do you have the Rest guide notes handy?

I am currently using v1.1.11 of the EpicorRestAPI. I see a RESTLOG option in the code. What would be the optimum placement for a Restlog statement to go, before the line causing the error, on the line causing the error, or after? Also, what would the RestLog statement look like?

Thanks to all of you helping with this!

Sure! :wink:

See pp 75-79.

Hi Dylan
It’s just a log all you need to do is look at it as it runs
Either print it’s result or put a break right after the error and take a look at that property

It will contain the whole request response etc

Actually @dgreenEA I just ran into an issue this morning that may be related…

I was having weird errors in REST myself and then I realized the account (user account) I was using had been logged on to the wrong COMPANY

So my REST calls I wasn’t explicitly indicating which company via the CallSettings header, now it couldn’t find a BAQ that used to be there…

So… give that a shot, set your CallSettings header and see if that makes things better.

Example Here:

Under the license example notice how I set the CallSettings header to company EPIC03



That helped a little bit. I still get the following error if I let the baq run wide open.

But it happens at the 1 minute 40 seconds mark every time. If I cut the data in half it seems to work properly now. Any idea why that seems to be happening?