"Using Module <moduleName>" not working in endpoints

I am currently writing a REST API using UD. I have a separate module with a number of PS Class definitions. I would like to be able to be able to call static methods from these custom PS Classes from api endpoints, but nothing I’ve tried so far seems to work. The best I’ve managed so far is to Install the module in the PS modules path, place a “using module moduleName” as the first line of my endpoint scriptblock, and see that the module is loaded in the sessions (via using get-module). However, when I try to instantiate an object from one of the classes in the module, or call a static method, I get a “Unable to find type [className]”.

Adding modules to the modules array in the New-UDEndpointInitialization will make modules available, but import-module won’t load the class definitions.

Anyone have any ideas?

I do the following, pass the name of my installed modules into the below function:
$dashmodules = @(“module1”,“module2”)
$endpointinitialization = New-UDEndpointInitialization -Variable $dashvariables -Function $dashfunctions -Module $dashmodules

When you do either new-uddashboard or start-udrestapi use the ‘-EndpointInitialization $endpointinitialization’ flag to pass it in.

1 Like

Hey,

this is a snippet how I’m using modules in UD.

so, for every page I create I write my own module. the reason is pretty simple, whenever i change something in the module it will only effect the page which is using the corresponding module. There is a modules folder where I put all my modules. You can import them like this:

$EI = New-UDEndpointInitialization -Module @(".\modules\module1.psm1", ".\modules\module2.psm1")

then you have to add the modules to your dashboard:

New-UDDashboard -EndpointInitialization $EI

finally, you can use your stuff in -Endpoint sections. content is static.

New-UDWhatEver -Endpoint {
   some code here ....
}

hope it helps.

Cheers

1 Like