Jellyfin Forum
Library Refresh Not Working on [HttpPost("Library/Refresh")] - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: Troubleshooting (https://forum.jellyfin.org/f-troubleshooting)
+---- Forum: Networking & Access (https://forum.jellyfin.org/f-networking-access)
+---- Thread: Library Refresh Not Working on [HttpPost("Library/Refresh")] (/t-library-refresh-not-working-on-httppost-library-refresh)



Library Refresh Not Working on [HttpPost("Library/Refresh")] - haw - 2024-03-25

I've been trying to troubleshoot an external app connectivity to a new Windows 11 install of Jellyfin this weekend, particularly an HTTP post to trigger a library refresh.

As I understand, it should work for http://192.168.1.30:8096/library/refresh?api_key=xxxxx

This fails for me.

I have no issues with network reachability for devices on either end. I can file transfer and ping both directions. I've got media folder sources at the other device, which Jellyfin reads fine. My issue appears to be with the Jellyfin server config.

When I'm authenticated in the browser for Jellyfin, I should be able to navigate to http://192.168.1.30:8096/library/refresh and trigger a library refresh with a 204 response for library scan started, right?

https://github.com/jellyfin/jellyfin/blob/master/Jellyfin.Api/Controllers/LibraryController.cs

/// <summary>
    /// Starts a library scan.
    /// </summary>
    /// <response code="204">Library scan started.</response>
    /// <returns>A <see cref="NoContentResult"/>.</returns>
    [HttpPost("Library/Refresh")]
    [Authorize(Policy = Policies.RequiresElevation)]
    [ProducesResponseType(StatusCodes.Status204NoContent)]
    public async Task<ActionResult> RefreshLibrary()
    {
        try
        {
            await _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error refreshing library");
        }

        return NoContent();
    }

When I use this URL, I get a 405 failure. I'm not sure where to look to investigate this issue further. Have I missed a setting to trigger refreshes in the web server? Am I using the wrong URL path?

My log file shows the request and session close but I only get the 405 error in the browser:

[2024-03-24 19:59:00.552 -04:00] [INF] [21] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.169" request
[2024-03-24 20:01:02.629 -04:00] [INF] [44] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.169" closed
[2024-03-24 20:16:26.797 -04:00] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "127.0.0.1" request
[2024-03-24 20:16:42.135 -04:00] [INF] [17] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "127.0.0.1" closed

To be clear, I cannot trigger a refresh from (1) the remote app with the API key or (2) from an authenticated session directly in the browser.

I'd be happy to be the idiot who missed a setting somewhere but I'm at a loss here. Any guidance would be appreciated.


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - TheDreadPirate - 2024-03-25

Keep in mind that you are looking at the master branch, which is currently the unreleased 10.9. If your setup is running 10.8.X you will need to switch to the 10.8.Z branch and make sure that your API call matches what is in the code there.


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - haw - 2024-03-25

Thanks.

To follow up, I see identical code in the 10.8.z branch. I'm currently running 10.8.13.

https://github.com/jellyfin/jellyfin/blob/release-10.8.z/Jellyfin.Api/Controllers/LibraryController.cs


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - haw - 2024-03-28

So, this is still driving me mad. Here's the API documentation telling me that this should work: https://api.jellyfin.org/#tag/Library/operation/RefreshLibrary


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - grunwalski - 2024-07-11

Same problem here. I could be just clueless, but I tried a lot by now.


Running in v10.9.7 in Docker

From a container in the same stack every one of these is met with a 401 / Request completley sent off:

Code:
curl -v -X POST "http://172.29.0.10:8096/Library/Refresh" -H "Authorization: ApiKeyCopiedFromJellyfin"
curl -v -X POST "http://172.29.0.10:8096/Library/Refresh" -H "Authorization: MediaBrowser ApiKeyCopiedFromJellyfin"
curl -v -X POST "http://172.29.0.10:8096/Library/Refresh" --user ApiKeyCopiedFromJellyfin:



Responses all come with the same result:

Code:
*  Trying 172.29.0.10:8096...
* Connected to 172.29.0.10 (172.29.0.10) port 8096
> POST /Library/Refresh HTTP/1.1
> Host: 172.29.0.10:8096
> User-Agent: curl/8.8.0
> Accept: */*
> Authorization: MediaBrowser ApiKeyCopiedFromJellyfin
>
* Request completely sent off
< HTTP/1.1 401 Unauthorized
< Content-Length: 0
< Date: Thu, 11 Jul 2024 14:10:05 GMT
< Server: Kestrel
< X-Response-Time-ms: 0.2319
<
* Connection #0 to host 172.29.0.10 left intact


And Jellyfin only logs
Code:
[INF] [42] Jellyfin.Api.Auth.CustomAuthenticationHandler: AuthenticationScheme: CustomAuthentication was challenged.


Right now, even with *arr connect webhooks, I cannot trigger a library refresh.
Any ideas would be greatly appreciated. I am out of them.


[edit:]just be sure, i've found posts where there was this in the logs. but i only get the challenged entry "CustomAuthentication was not authenticated. Failure message: Invalid token." Cn.


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - niels - 2024-07-11

Your authorization header is formatted incorrectly.

See https://gist.github.com/nielsvanvelzen/ea047d9028f676185832e51ffaf12a6f


RE: Library Refresh Not Working on [HttpPost("Library/Refresh")] - grunwalski - 2024-07-11

THANKS. This was a clear case of: once you stop doing it wrong, it just works.