-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.sh
More file actions
executable file
·92 lines (75 loc) · 2.04 KB
/
Copy pathtest-api.sh
File metadata and controls
executable file
·92 lines (75 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Test script for AnkiConnect API
set -e
ANKI_HOST=${ANKI_HOST:-localhost}
ANKI_PORT=${ANKI_PORT:-8765}
BASE_URL="http://${ANKI_HOST}:${ANKI_PORT}"
echo "Testing AnkiConnect API at ${BASE_URL}"
# Function to make API request
api_request() {
local action="$1"
local params="$2"
local version="${3:-6}"
if [ -z "$params" ]; then
params="{}"
fi
local data=$(cat <<EOF
{
"action": "$action",
"version": $version,
"params": $params
}
EOF
)
echo "Testing: $action"
response=$(curl -s -X POST "$BASE_URL" \
-H "Content-Type: application/json" \
-d "$data")
if echo "$response" | grep -q '"error":null'; then
echo "✅ $action - SUCCESS"
echo "Response: $response"
else
echo "❌ $action - FAILED"
echo "Response: $response"
return 1
fi
echo ""
}
# Test basic connectivity
echo "🔍 Checking AnkiConnect connectivity..."
if ! curl -s --max-time 5 "$BASE_URL" > /dev/null; then
echo "❌ Cannot connect to AnkiConnect at $BASE_URL"
echo "Make sure the container is running: docker-compose ps"
exit 1
fi
echo "✅ Successfully connected to AnkiConnect"
echo ""
# Test API endpoints
echo "🧪 Running API tests..."
# Test version
api_request "version"
# Test deck names
api_request "deckNames"
# Test model names
api_request "modelNames"
# Test creating a note (optional - only if Default deck exists)
echo "📝 Testing note creation..."
note_params='{
"note": {
"deckName": "Default",
"modelName": "Basic",
"fields": {
"Front": "Docker Test Card",
"Back": "This is a test card created by the API test script"
},
"tags": ["docker-test", "api-test"]
}
}'
if api_request "addNote" "$note_params"; then
echo "✅ Note creation test passed"
else
echo "⚠️ Note creation test failed (this might be normal if Default deck doesn't exist)"
fi
echo ""
echo "🎉 API testing completed!"
echo "AnkiConnect is working correctly at $BASE_URL"