Call Function with a button click

I set up the CallService and StreamWriter as suggested but I still get the same error.

How do I verify the client’s auth vs the server’s auth? I would have thought that setting the APIKey up would have created the proper environment for making a call like this.

API Key provides access scope, user provides security.

What does your API Key setup look like. Do you have OH_Updates included in the access scope for that API Key?

I have created a new Access Scope, put in my BAQ, Library, and Function. I tied that access scope to the API Key but still no luck.

Is your function published?

1 Like

What version of Epicor are you on?

We are on 10.2.600 and it is not published. I have changed the flag to false but that doesn’t help either.

This is getting more complicated than it is worth. The person who would be executing the function is smart enough and has the permissions to kick it off with the Schedule Epicor Function. I am going to abandon the button click process. Thanks for all of the advice!

Did you try publishing it? It might require the function to be published (even with the false true options)

You could use my function runner BAQ. No REST required.
I’m not sure I explained it well when I posted it, but I can if you want to try.

I just used it myself in dashboard.

2 Likes

I decided to make another attempt at calling a function from a button click.

I am calling a different function than before. This one does not take any parameters. I have this code in my button click event:

const string apiKey = "U3FoF6HadakgFQ9LrwFN*****";

try {
var restClient = new RestClientBuilder()
				.SetDefaultApiKey(apiKey)
				.UseSession(oTrans.CoreSession)
				.Build();

var functionContent = new RestContent(new{});

var functionResponse = restClient.Function.Post("MyLibrary", "GetWBSDates", functionContent, published: true);
}
catch (System.IO.IOException e)
{
     // If just catching and then immediately rethrowing then consider not catching the 
     // exception here to avoid making it look like exceptions are happening in multiple areas.
     // Maybe catch where you are calling CallPostFunction instead.  Doing it this way will just
     // generate a new exception with an identical exception in the InnerException property.  
     // Just a suggestion.
     throw new System.IO.IOException("IO REST Call", e);
}
catch (Exception e)
{
     // Keeping this catch will cover any other unhandled exceptions that might come up
     throw new Exception("REST Call", e);
}

My library is published. I have only one company so I know my permissions are fine. I keep getting this generic REST error and I have no idea how to determine what is wrong.

Any help/advice is appreciated!