Device Auto Accept

aaaand several trial-and-error-bing-copilot hours later, auto share the default folder to all previously auto accepted devices (note the direction, from our introducer to the others, not accepting their offers - that is syncthing cli config devices "$DEVICE_ID" auto-accept-folders set true)

$ cat add-all-pending-folders.sh
#!/bin/bash

# Set your Syncthing API key and base URL
API_KEY="x"
BASE_URL="https://x:8384"
FOLDER_ID="default"  # Replace with your actual folder ID

# Get the list of pending folders
PENDING_FOLDERS=$(curl -s -k -X GET -H "X-API-Key: $API_KEY" "$BASE_URL/rest/cluster/pending/folders")

# Extract device IDs from the pending folders list
DEVICE_IDS=($(echo "$PENDING_FOLDERS" | jq -r '.[].offeredBy | keys[]'))

# Check if any device IDs were found
if [ ${#DEVICE_IDS[@]} -eq 0 ]; then
    exit 0
fi

# Iterate through each device ID and add it to the JSON payload
for DEVICE_ID in "${DEVICE_IDS[@]}"; do
        echo syncthing cli config folders "default" devices add --device-id="$DEVICE_ID"
        syncthing cli config folders "default" devices add --device-id="$DEVICE_ID"
done

and yes it’s slower than using the way the gui does it because it serializes adding, but it’s easier for me.

2 Likes