| Posted by: WUICTeam - Thursday, November 19, 2026 9:01:08 AM |
|---|
| [b]Question[/b] I created a scheduler job with [c]action_type = 2[/c] and [c]action_cmd[/c] set to [c]POST https://crm.example.com/api/invoices/reminders[/c], which is an endpoint of the same app. The job runs, but the endpoint answers 401. Calling it by hand with a logged-in user works. What is going on? [b]Answer[/b] The scheduler sends its [c]__scheduler[/c] login and cookie only to the backend it is running in. An absolute URL that points to your public host name is, for the scheduler, just another server: the call is made [i]without credentials[/i], so a protected endpoint answers 401. [b]What counts as "this backend"[/b] [list] [*]a loopback host (for example [c]localhost[/c]) on a port the process is listening on; [*]a URL listed in [c]Scheduler.TrustedAuthBaseUrls[/c]: scheme, host and port must match (the path is not compared). [/list] [b]Two ways to fix it[/b] [list=1] [*]Use a relative URL. A path starting with [c]/[/c] is resolved on the address of the running app, so the host name never appears in the job: [c]POST /api/invoices/reminders[/c]. Without a verb the call is a [c]POST[/c]. [*]Keep the absolute URL and declare it as trusted in [c]appsettings.json[/c]: [/list] [code] "Scheduler": { "TrustedAuthBaseUrls": [ "https://crm.example.com" ] } [/code] Relative URLs are resolved on the first entry of that list when it is set, otherwise on a loopback address the process listens on. If neither is available (unix socket, only non-loopback bindings, IIS out-of-process) the job fails with an error asking you to set the key. Set it also when the IIS site answers only to a host name, and include the sub-application path if there is one, e.g. [c]https://crm.example.com/CrmApp[/c]. [b]Pitfall[/b] Relative URLs cannot leave the app: [c]//host/...[/c], backslashes and paths like [c]/../OtherApp/...[/c] are rejected. Don't use them to reach another service; for that, use an absolute URL, knowing that no credentials will be sent. [url=https://wuic-framework.com/docs/scheduling]Documentation: Scheduling[/url] |