• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Support General Questions API endpoint to scan a single library

     
    • 0 Vote(s) - 0 Average

    API endpoint to scan a single library

    alextruppel
    Offline

    Junior Member

    Posts: 1
    Threads: 1
    Joined: 2025 Feb
    Reputation: 0
    #1
    2025-02-12, 01:47 PM
    Hi everyone! I know this can be used to trigger a scan of all libraries in Jellyfin:

    Code:
    http://jellyfin-ip-etc.../library/refresh?api_key=my-api-key

    But is there a way to trigger a refresh of just a single library? This is because I have multiple libraries, some smaller libraries have new files being constantly added, whereas some large libraries almost never change and also take easily 1 hour or more to scan, not to mention that they pull 80MB/s from my NAS during the entire time of the scan. Ideally, I'd be able to trigger a re-scan of only some libraries when they change.

    Thank you!
    TheDreadPirate
    Offline

    Community Moderator

    Posts: 15,374
    Threads: 10
    Joined: 2023 Jun
    Reputation: 462
    Country:United States
    #2
    2025-02-12, 04:38 PM
    When I go to Dashboard > Libraries, and scan for updates on an individual library I see this in the browser developer console.

    Code:
    https://jellyfin-testing.domain.tld/Items/f137a2dd21bbc1b99aa5c0f6bf02a805/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&RegenerateTrickplay=false&ReplaceAllMetadata=false

    Looks like the library has an Items ID that you need to use?
    Jellyfin 10.10.7 (Docker)
    Ubuntu 24.04.2 LTS w/HWE
    Intel i3 12100
    Intel Arc A380
    OS drive - SK Hynix P41 1TB
    Storage
        4x WD Red Pro 6TB CMR in RAIDZ1
    [Image: GitHub%20Sponsors-grey?logo=github]
    arjuan
    Offline

    Junior Member

    Posts: 1
    Threads: 0
    Joined: 2025 Mar
    Reputation: 0
    #3
    2025-03-31, 09:32 PM
    The API documentation is a good place to start for this type of question Smiling-face

    https://api.jellyfin.org/#tag/Library/op...datedMedia

    Here's an example cURL query to update a specific library path:


    curl -H "X-MediaBrowser-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d '{"Updates": [{"Path":"/path/to/folder/","UpdateType":"scan"}]}' https://jellyfin.example.com/Library/Media/Updated
    I-G-1-1
    Offline

    Junior Member

    Posts: 34
    Threads: 5
    Joined: 2023 Jun
    Reputation: 0
    #4
    2025-07-11, 03:13 PM (This post was last modified: 2025-07-12, 11:03 AM by I-G-1-1. Edited 1 time in total.)
    I know this post is old, but to trigger a single Library scan thanks to "url scheme" suggested by TheDreadPirate I solved writing this script:

    Code:
    #!/bin/sh

    # CHANGE THESE:
    JELLYFIN_SERVER="http://192.168.1.1:8096"
    API_KEY="<YOUR_API_KEY>"

    echo "Retrieving available libraries..."

    # Get the list of libraries from the Jellyfin server using the API key for authentication
    LIBRARIES=$(curl -s -H "X-Emby-Token: $API_KEY" "$JELLYFIN_SERVER/Library/VirtualFolders")

    # Extract the names of the libraries from the JSON response
    NAMES=$(echo "$LIBRARIES" | grep -o '"Name":"[^"]*"' | sed 's/"Name":"\(.*\)"/\1/')
    # Extract the IDs of the libraries from the JSON response
    IDS=$(echo "$LIBRARIES" | grep -o '"ItemId":"[^"]*"' | sed 's/"ItemId":"\(.*\)"/\1/')

    # Combine and print the name and ID of each library in a readable format
    paste <(echo "$NAMES") <(echo "$IDS") | while IFS=$'\t' read -r name id; do
      echo "Name: $name | ID: $id"
    done

    echo
    read -p "Enter the ID of the library to scan: " LIBRARY_ID

    if [[ -z "$LIBRARY_ID" ]]; then
      echo "Library ID not provided. Exiting."
      exit 1
    fi

    echo "Starting scan of library $LIBRARY_ID ..."
    # Send a POST request to trigger a scan/refresh of the specified library on the Jellyfin server
    curl -X POST "$JELLYFIN_SERVER/Items/$LIBRARY_ID/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&RegenerateTrickplay=false&ReplaceAllMetadata=false" \
      -H "Content-Type: application/json" \
      -H "X-Emby-Token: $API_KEY"

    echo
    echo "Scan started (check the Jellyfin dashboard for status)."

    exit 0
    SenileOtaku
    Offline

    Junior Member

    Posts: 24
    Threads: 5
    Joined: 2023 Jun
    Reputation: 1
    Country:United States
    #5
    2025-08-23, 12:22 AM
    (2025-07-11, 03:13 PM)I-G-1-1 Wrote: I know this post is old, but to trigger a single Library scan thanks to "url scheme" suggested by TheDreadPirate I solved writing this script:

    I tried the script but it failed at:

    bin/refresh-jellyfin.sh: 35: Syntax error: "(" unexpected

    that would be the line:
    Code:
    paste <(echo "$NAMES") <(echo "$IDS") | while IFS=$'\t' read -r name id; do

    in the section:
    Code:
    # Combine and print the name and ID of each library in a readable format
    paste <(echo "$NAMES") <(echo "$IDS") | while IFS=$'\t' read -r name id; do
      echo "Name: $name | ID: $id"
    done
    Azruzagar
    Offline

    Junior Member

    Posts: 1
    Threads: 0
    Joined: 2025 Sep
    Reputation: 0
    Country:Sweden
    #6
    5 hours ago
    I ran into the same problem, but I gave the code to Chat-GPT to rewrite.

    Code:
    #!/usr/bin/env bash
    set -o errexit
    set -o nounset
    set -o pipefail

    JELLYFIN_SERVER="http://server_ip"
    API_KEY="YOUR-API-Key"

    trap 'printf "Script interrupted.\n" >&2; exit 1' INT TERM

    fetch_libraries() {
        local response
        if ! response=$(curl -s -H "X-Emby-Token: $API_KEY" "$JELLYFIN_SERVER/Library/VirtualFolders"); then
            printf "Failed to retrieve libraries from Jellyfin server.\n" >&2
            return 1
        fi
        if [[ -z "${response//[[:space:]]/}" ]]; then
            printf "Empty response received from Jellyfin server.\n" >&2
            return 1
        fi
        printf "%s" "$response"
    }

    extract_names() {
        local data="$1"
        local names
        if ! names=$(printf "%s" "$data" | grep -o '"Name":"[^"]*"' | sed 's/"Name":"\(.*\)"/\1/'); then
            printf "Failed to extract names from JSON response.\n" >&2
            return 1
        fi
        if [[ -z "${names//[[:space:]]/}" ]]; then
            printf "No library names found in JSON response.\n" >&2
            return 1
        fi
        printf "%s" "$names"
    }

    extract_ids() {
        local data="$1"
        local ids
        if ! ids=$(printf "%s" "$data" | grep -o '"ItemId":"[^"]*"' | sed 's/"ItemId":"\(.*\)"/\1/'); then
            printf "Failed to extract IDs from JSON response.\n" >&2
            return 1
        fi
        if [[ -z "${ids//[[:space:]]/}" ]]; then
            printf "No library IDs found in JSON response.\n" >&2
            return 1
        fi
        printf "%s" "$ids"
    }

    print_libraries() {
        local names="$1"
        local ids="$2"
        paste <(printf "%s\n" "$names") <(printf "%s\n" "$ids") | while IFS=$'\t' read -r name id; do
            printf "Name: %s | ID: %s\n" "$name" "$id"
        done
    }

    scan_library() {
        local library_id="$1"
        if [[ -z "${library_id//[[:space:]]/}" ]]; then
            printf "Library ID not provided. Exiting.\n" >&2
            return 1
        fi
        printf "Starting scan of library %s ...\n" "$library_id"
        if ! curl -s -X POST \
            "$JELLYFIN_SERVER/Items/$library_id/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&RegenerateTrickplay=false&ReplaceAllMetadata=false" \
            -H "Content-Type: application/json" \
            -H "X-Emby-Token: $API_KEY" >/dev/null; then
            printf "Failed to start scan for library %s.\n" "$library_id" >&2
            return 1
        fi
        printf "Scan started (check the Jellyfin dashboard for status).\n"
    }

    main() {
        printf "Retrieving available libraries...\n"
        local libraries names ids library_id
        libraries=$(fetch_libraries) || return 1
        names=$(extract_names "$libraries") || return 1
        ids=$(extract_ids "$libraries") || return 1
        print_libraries "$names" "$ids"
        printf "\n"
        read -r -p "Enter the ID of the library to scan: " library_id
        scan_library "$library_id" || return 1
    }

    main "$@"

    Code:
    Retrieving available libraries...
    Name: TV | ID: 4514ec850e5ad0c47b58444e17b6346c
    Name: Movies | ID: f137a2dd21bbc1b99aa5c0f6bf02a805

    Enter the ID of the library to scan: e2c00f297a5f80af390f52f72e782147
    Starting scan of library e2c00f297a5f80af390f52f72e782147 ...
    Scan started (check the Jellyfin dashboard for status).
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode