initial
This commit is contained in:
Executable
+259
@@ -0,0 +1,259 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Keitaro API CLI Helper
|
||||
# Makes it easier to interact with Keitaro API from command line
|
||||
|
||||
set -e
|
||||
|
||||
# Load credentials from .env if it exists
|
||||
if [ -f "$(dirname "$0")/.env" ]; then
|
||||
export $(grep -v '^#' "$(dirname "$0")/.env" | xargs)
|
||||
fi
|
||||
|
||||
# Check for required environment variables
|
||||
if [ -z "$KEITARO_DOMAIN" ] || [ -z "$KEITARO_API_KEY" ]; then
|
||||
echo "Error: KEITARO_DOMAIN and KEITARO_API_KEY must be set"
|
||||
echo "Either set them as environment variables or create a .env file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_URL="https://${KEITARO_DOMAIN}/admin_api/v1"
|
||||
|
||||
# Helper function to make API requests
|
||||
keitaro_request() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
|
||||
if [ -n "$data" ]; then
|
||||
response=$(curl -s -w "\n%{http_code}" -X "$method" \
|
||||
-H "Api-Key: $KEITARO_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data" \
|
||||
"${BASE_URL}${endpoint}")
|
||||
else
|
||||
response=$(curl -s -w "\n%{http_code}" -X "$method" \
|
||||
-H "Api-Key: $KEITARO_API_KEY" \
|
||||
"${BASE_URL}${endpoint}")
|
||||
fi
|
||||
|
||||
http_code=$(echo "$response" | tail -n1)
|
||||
body=$(echo "$response" | sed '$d')
|
||||
|
||||
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body"
|
||||
else
|
||||
echo "Error $http_code:" >&2
|
||||
echo "$body" | jq . 2>/dev/null || echo "$body" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Command dispatcher
|
||||
case "$1" in
|
||||
# Affiliate Networks
|
||||
"networks:list")
|
||||
keitaro_request GET "/affiliate_networks"
|
||||
;;
|
||||
"networks:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 networks:get <id>" && exit 1
|
||||
keitaro_request GET "/affiliate_networks/$2"
|
||||
;;
|
||||
"networks:create")
|
||||
[ -z "$2" ] && echo "Usage: $0 networks:create <name> [postback_url]" && exit 1
|
||||
data="{\"name\":\"$2\""
|
||||
[ -n "$3" ] && data="$data,\"postback_url\":\"$3\""
|
||||
data="$data}"
|
||||
keitaro_request POST "/affiliate_networks" "$data"
|
||||
;;
|
||||
"networks:delete")
|
||||
[ -z "$2" ] && echo "Usage: $0 networks:delete <id>" && exit 1
|
||||
keitaro_request DELETE "/affiliate_networks/$2"
|
||||
;;
|
||||
|
||||
# Offers
|
||||
"offers:list")
|
||||
keitaro_request GET "/offers"
|
||||
;;
|
||||
"offers:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 offers:get <id>" && exit 1
|
||||
keitaro_request GET "/offers/$2"
|
||||
;;
|
||||
"offers:create")
|
||||
[ -z "$2" ] && echo "Usage: $0 offers:create '<json>'" && exit 1
|
||||
keitaro_request POST "/offers" "$2"
|
||||
;;
|
||||
"offers:clone")
|
||||
[ -z "$2" ] || [ -z "$3" ] && echo "Usage: $0 offers:clone <id> <new_name>" && exit 1
|
||||
keitaro_request POST "/offers/$2/clone" "{\"name\":\"$3\"}"
|
||||
;;
|
||||
|
||||
# Campaigns
|
||||
"campaigns:list")
|
||||
keitaro_request GET "/campaigns?offset=0&limit=100"
|
||||
;;
|
||||
"campaigns:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 campaigns:get <id>" && exit 1
|
||||
keitaro_request GET "/campaigns/$2"
|
||||
;;
|
||||
"campaigns:create")
|
||||
[ -z "$2" ] || [ -z "$3" ] && echo "Usage: $0 campaigns:create <name> <alias>" && exit 1
|
||||
keitaro_request POST "/campaigns" "{\"name\":\"$2\",\"alias\":\"$3\"}"
|
||||
;;
|
||||
"campaigns:enable")
|
||||
[ -z "$2" ] && echo "Usage: $0 campaigns:enable <id>" && exit 1
|
||||
keitaro_request POST "/campaigns/$2/enable"
|
||||
;;
|
||||
"campaigns:disable")
|
||||
[ -z "$2" ] && echo "Usage: $0 campaigns:disable <id>" && exit 1
|
||||
keitaro_request POST "/campaigns/$2/disable"
|
||||
;;
|
||||
"campaigns:streams")
|
||||
[ -z "$2" ] && echo "Usage: $0 campaigns:streams <id>" && exit 1
|
||||
keitaro_request GET "/campaigns/$2/streams"
|
||||
;;
|
||||
|
||||
# Domains
|
||||
"domains:list")
|
||||
keitaro_request GET "/domains"
|
||||
;;
|
||||
"domains:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 domains:get <id>" && exit 1
|
||||
keitaro_request GET "/domains/$2"
|
||||
;;
|
||||
"domains:create")
|
||||
[ -z "$2" ] && echo "Usage: $0 domains:create <name>" && exit 1
|
||||
keitaro_request POST "/domains" "{\"name\":\"$2\",\"state\":\"active\"}"
|
||||
;;
|
||||
"domains:check")
|
||||
[ -z "$2" ] && echo "Usage: $0 domains:check <id>" && exit 1
|
||||
keitaro_request POST "/domains/$2/check"
|
||||
;;
|
||||
"domains:ip")
|
||||
keitaro_request GET "/domains/ip"
|
||||
;;
|
||||
|
||||
# Landing Pages
|
||||
"landings:list")
|
||||
keitaro_request GET "/landing_pages"
|
||||
;;
|
||||
"landings:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 landings:get <id>" && exit 1
|
||||
keitaro_request GET "/landing_pages/$2"
|
||||
;;
|
||||
|
||||
# Statistics
|
||||
"stats:clicks")
|
||||
[ -z "$2" ] && echo "Usage: $0 stats:clicks '<json>'" && exit 1
|
||||
keitaro_request POST "/clicks/log" "$2"
|
||||
;;
|
||||
"stats:conversions")
|
||||
[ -z "$2" ] && echo "Usage: $0 stats:conversions '<json>'" && exit 1
|
||||
keitaro_request POST "/conversions/log" "$2"
|
||||
;;
|
||||
|
||||
# Bot List
|
||||
"botlist:get")
|
||||
keitaro_request GET "/botlist"
|
||||
;;
|
||||
"botlist:add")
|
||||
[ -z "$2" ] && echo "Usage: $0 botlist:add '<json_array>'" && exit 1
|
||||
keitaro_request POST "/botlist/add" "{\"ips\":$2}"
|
||||
;;
|
||||
"botlist:remove")
|
||||
[ -z "$2" ] && echo "Usage: $0 botlist:remove '<json_array>'" && exit 1
|
||||
keitaro_request POST "/botlist/exclude" "{\"ips\":$2}"
|
||||
;;
|
||||
|
||||
# Groups
|
||||
"groups:list")
|
||||
[ -z "$2" ] && echo "Usage: $0 groups:list <type> (campaigns|offers|landings|domains)" && exit 1
|
||||
keitaro_request GET "/groups?type=$2"
|
||||
;;
|
||||
"groups:create")
|
||||
[ -z "$2" ] || [ -z "$3" ] && echo "Usage: $0 groups:create <name> <type>" && exit 1
|
||||
keitaro_request POST "/groups" "{\"name\":\"$2\",\"type\":\"$3\"}"
|
||||
;;
|
||||
|
||||
# Integrations
|
||||
"fb:list")
|
||||
keitaro_request GET "/integrations/facebook"
|
||||
;;
|
||||
"fb:get")
|
||||
[ -z "$2" ] && echo "Usage: $0 fb:get <id>" && exit 1
|
||||
keitaro_request GET "/integrations/facebook/$2"
|
||||
;;
|
||||
|
||||
# Help
|
||||
"help"|"--help"|"-h"|"")
|
||||
cat << EOF
|
||||
Keitaro API CLI Helper
|
||||
|
||||
Usage: $0 <command> [arguments]
|
||||
|
||||
Affiliate Networks:
|
||||
networks:list - List all affiliate networks
|
||||
networks:get <id> - Get network by ID
|
||||
networks:create <name> [url] - Create network
|
||||
networks:delete <id> - Delete network
|
||||
|
||||
Offers:
|
||||
offers:list - List all offers
|
||||
offers:get <id> - Get offer by ID
|
||||
offers:create '<json>' - Create offer (pass JSON)
|
||||
offers:clone <id> <new_name> - Clone offer
|
||||
|
||||
Campaigns:
|
||||
campaigns:list - List all campaigns
|
||||
campaigns:get <id> - Get campaign by ID
|
||||
campaigns:create <name> <alias> - Create campaign
|
||||
campaigns:enable <id> - Enable campaign
|
||||
campaigns:disable <id> - Disable campaign
|
||||
campaigns:streams <id> - Get campaign streams
|
||||
|
||||
Domains:
|
||||
domains:list - List all domains
|
||||
domains:get <id> - Get domain by ID
|
||||
domains:create <name> - Create domain
|
||||
domains:check <id> - Check domain status
|
||||
domains:ip - Get server IP
|
||||
|
||||
Landing Pages:
|
||||
landings:list - List all landing pages
|
||||
landings:get <id> - Get landing page by ID
|
||||
|
||||
Statistics:
|
||||
stats:clicks '<json>' - Query click statistics
|
||||
stats:conversions '<json>' - Query conversions
|
||||
|
||||
Bot List:
|
||||
botlist:get - Get bot list
|
||||
botlist:add '<json_array>' - Add IPs to bot list
|
||||
botlist:remove '<json_array>' - Remove IPs from bot list
|
||||
|
||||
Groups:
|
||||
groups:list <type> - List groups by type
|
||||
groups:create <name> <type> - Create group
|
||||
|
||||
Integrations:
|
||||
fb:list - List Facebook integrations
|
||||
fb:get <id> - Get Facebook integration
|
||||
|
||||
Examples:
|
||||
$0 networks:create "MaxBounty" "https://maxbounty.com/postback"
|
||||
$0 campaigns:create "Summer Sale" "summer-sale"
|
||||
$0 offers:clone 123 "New Offer Name"
|
||||
$0 stats:clicks '{"range":{"from":"2026-01-01","to":"2026-01-31","timezone":"UTC"},"columns":["clicks"],"metrics":["clicks"]}'
|
||||
|
||||
Configuration:
|
||||
Set KEITARO_DOMAIN and KEITARO_API_KEY environment variables
|
||||
Or create a .env file in the skill directory
|
||||
|
||||
EOF
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $1"
|
||||
echo "Run '$0 help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Keitaro API Test Examples
|
||||
# Demonstrates various API operations
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
CLI="$SCRIPT_DIR/keitaro-cli.sh"
|
||||
|
||||
echo "========================================="
|
||||
echo "Keitaro API Skill - Test Examples"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Test 1: List affiliate networks
|
||||
echo "1. Listing affiliate networks..."
|
||||
echo "Command: $CLI networks:list"
|
||||
$CLI networks:list | jq -r '.[] | "\(.id): \(.name)"' | head -5
|
||||
echo ""
|
||||
|
||||
# Test 2: Get specific network
|
||||
echo "2. Getting specific network (ID: 77)..."
|
||||
echo "Command: $CLI networks:get 77"
|
||||
$CLI networks:get 77 | jq '{id, name, postback_url}'
|
||||
echo ""
|
||||
|
||||
# Test 3: List offers
|
||||
echo "3. Listing offers..."
|
||||
echo "Command: $CLI offers:list"
|
||||
$CLI offers:list | jq -r 'if type == "array" then .[] | "\(.id): \(.name)" else "No offers found" end' | head -5
|
||||
echo ""
|
||||
|
||||
# Test 4: List campaigns
|
||||
echo "4. Listing campaigns..."
|
||||
echo "Command: $CLI campaigns:list"
|
||||
$CLI campaigns:list | jq -r 'if type == "array" then .[] | "\(.id): \(.name) (\(.alias))" else "No campaigns found" end' | head -5
|
||||
echo ""
|
||||
|
||||
# Test 5: List domains
|
||||
echo "5. Listing domains..."
|
||||
echo "Command: $CLI domains:list"
|
||||
$CLI domains:list | jq -r 'if type == "array" then .[] | "\(.id): \(.name) - \(.state)" else "No domains found" end' | head -5
|
||||
echo ""
|
||||
|
||||
# Test 6: Get server IP
|
||||
echo "6. Getting server IP..."
|
||||
echo "Command: $CLI domains:ip"
|
||||
$CLI domains:ip | jq .
|
||||
echo ""
|
||||
|
||||
# Test 7: List groups
|
||||
echo "7. Listing campaign groups..."
|
||||
echo "Command: $CLI groups:list campaigns"
|
||||
$CLI groups:list campaigns | jq -r 'if type == "array" then .[] | "\(.id): \(.name)" else "No groups found" end' | head -5
|
||||
echo ""
|
||||
|
||||
echo "========================================="
|
||||
echo "All tests completed successfully!"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "You can now use the Keitaro API skill with Claude Code."
|
||||
echo "Try asking: 'List all affiliate networks in Keitaro'"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user