cURL Examples
Practical cURL command examples for integrating with the Zaits API using HTTP requests.
Authentication
All API requests require authentication using your API key in the Authorization header:
curl -H "Authorization: Bearer YOUR_API_KEY" \
https://api.zaits.net/v1/endpointFace Recognition Examples
Face Verification
# Basic face verification
curl -X POST https://api.zaits.net/v1/face/verify \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image1=@./photo1.jpg" \
-F "image2=@./photo2.jpg"Face Analysis
# Analyze face for age, gender, and emotion
curl -X POST https://api.zaits.net/v1/face/analyze \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@./face.jpg" \
-F 'actions=["age", "gender", "emotion"]'Face Detection
# Detect all faces in an image
curl -X POST https://api.zaits.net/v1/face/detect \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@./group_photo.jpg" \
-F "min_confidence=0.8"Liveness Detection
# Check if face is live (anti-spoofing)
curl -X POST https://api.zaits.net/v1/face/liveness \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@./selfie.jpg" \
-F "threshold=0.7"OCR Examples
Text Extraction
# Extract text from document
curl -X POST https://api.zaits.net/v1/ocr/extract \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "document=@./invoice.pdf"# Extract with options
curl -X POST https://api.zaits.net/v1/ocr/extract \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "document=@./document.jpg" \
-F "language=en" \
-F "extract_tables=true" \
-F "output_format=structured"Document Analysis
# Analyze document and extract fields
curl -X POST https://api.zaits.net/v1/ocr/analyze \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "document=@./contract.pdf" \
-F "document_type=contract" \
-F 'extract_fields=["date", "amount", "parties"]'Document Signing Examples
Create Signing Request
# Create document signing request
curl -X POST https://api.zaits.net/v1/signing/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": "./contract.pdf",
"signers": [
{
"name": "John Doe",
"email": "[email protected]",
"role": "client"
},
{
"name": "Jane Smith",
"email": "[email protected]",
"role": "provider"
}
],
"title": "Service Agreement",
"message": "Please review and sign this agreement.",
"expires_in": "30d"
}'Check Signing Status
# Get signing status
curl -X GET https://api.zaits.net/v1/signing/status/DOC_ID \
-H "Authorization: Bearer YOUR_API_KEY"Download Signed Document
# Download signed document
curl -X GET https://api.zaits.net/v1/signing/download/DOC_ID \
-H "Authorization: Bearer YOUR_API_KEY" \
-o "signed_document.pdf"Usage Analytics Examples
Get Usage Summary
# Get current usage summary
curl -X GET https://api.zaits.net/v1/usage/summary \
-H "Authorization: Bearer YOUR_API_KEY"Get Detailed Statistics
# Get detailed usage statistics with filters
curl -X GET "https://api.zaits.net/v1/usage/stats?start_date=2024-01-01&end_date=2024-01-31&limit=100" \
-H "Authorization: Bearer YOUR_API_KEY"Deployment Management Examples
List Deployments
# List all deployments
curl -X GET https://api.zaits.net/api/deployments \
-H "Authorization: Bearer YOUR_API_KEY"Create Deployment
# Create new deployment
curl -X POST https://api.zaits.net/api/deployments/create \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"clientId": "acme-corp",
"clientName": "ACME Corporation",
"domain": "acme.yourapp.com",
"platform": "web",
"environment": "production",
"config": {
"primaryColor": "#007bff",
"logo": "https://acme.com/logo.png",
"companyName": "ACME Corp"
}
}'Get Deployment Status
# Check deployment status
curl -X GET https://api.zaits.net/api/deployments/DEPLOYMENT_ID/status \
-H "Authorization: Bearer YOUR_API_KEY"Advanced cURL Techniques
Using Variables and Scripts
#!/bin/bash
# Set your API key
API_KEY="your_api_key_here"
BASE_URL="https://api.zaits.net"
# Function to make API calls with error handling
make_api_call() {
local endpoint=$1
local method=$2
local data=$3
response=$(curl -s -w "\n%{http_code}" \
-X "$method" \
-H "Authorization: Bearer $API_KEY" \
"$BASE_URL$endpoint" \
$data)
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n -1)
if [ "$http_code" -eq 200 ]; then
echo "โ
Success: $endpoint"
echo "$body" | jq .
else
echo "โ Error $http_code: $endpoint"
echo "$body" | jq .
fi
}
# Example usage
make_api_call "/v1/usage/summary" "GET"Batch Processing with cURL
#!/bin/bash
API_KEY="your_api_key_here"
IMAGE_DIR="./images"
# Process all images in directory
for image in "$IMAGE_DIR"/*.jpg; do
echo "๐ Analyzing: $(basename "$image")"
curl -X POST https://api.zaits.net/v1/face/analyze \
-H "Authorization: Bearer $API_KEY" \
-F "image=@$image" \
-F 'actions=["age", "gender", "emotion"]' \
-o "results/$(basename "$image" .jpg)_analysis.json"
sleep 1 # Rate limiting
done
echo "โ
Batch processing complete!"Error Handling and Retries
#!/bin/bash
API_KEY="your_api_key_here"
MAX_RETRIES=3
RETRY_DELAY=2
make_api_call_with_retry() {
local endpoint=$1
local method=$2
local data=$3
local attempt=1
while [ $attempt -le $MAX_RETRIES ]; do
echo "๐ Attempt $attempt/$MAX_RETRIES for $endpoint"
response=$(curl -s -w "\n%{http_code}" \
-X "$method" \
-H "Authorization: Bearer $API_KEY" \
"https://api.zaits.net$endpoint" \
$data)
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n -1)
case $http_code in
200)
echo "โ
Success on attempt $attempt"
echo "$body" | jq .
return 0
;;
429)
echo "โณ Rate limited. Waiting ${RETRY_DELAY}s..."
sleep $RETRY_DELAY
;;
5*)
echo "๐ Server error $http_code. Retrying..."
sleep $RETRY_DELAY
;;
*)
echo "โ Client error $http_code. Not retrying."
echo "$body" | jq .
return 1
;;
esac
attempt=$((attempt + 1))
RETRY_DELAY=$((RETRY_DELAY * 2)) # Exponential backoff
done
echo "โ Failed after $MAX_RETRIES attempts"
return 1
}
# Example usage
make_api_call_with_retry "/v1/face/verify" "POST" "-F [email protected] -F [email protected]"File Upload with Progress
# Upload large file with progress bar
curl -X POST https://api.zaits.net/v1/ocr/extract \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "document=@./large_document.pdf" \
--progress-bar \
-o response.jsonJSON Response Processing with jq
#!/bin/bash
API_KEY="your_api_key_here"
# Get usage summary and extract specific fields
response=$(curl -s -X GET https://api.zaits.net/v1/usage/summary \
-H "Authorization: Bearer $API_KEY")
# Check if request was successful
if echo "$response" | jq -e '.success' > /dev/null; then
echo "๐ Usage Statistics:"
echo " Current month calls: $(echo "$response" | jq -r '.summary.current_month_calls')"
echo " Remaining calls: $(echo "$response" | jq -r '.summary.remaining_calls')"
echo " Percent used: $(echo "$response" | jq -r '.summary.percent_used')%"
echo "\n๐ Usage by endpoint:"
echo "$response" | jq -r '.by_endpoint | to_entries[] | " \(.key): \(.value)"'
else
echo "โ API request failed:"
echo "$response" | jq -r '.error.message'
fiConfiguration File for API Keys
# config.sh
API_KEY_PROD="sk_live_your_production_key"
API_KEY_TEST="sk_test_your_test_key"
BASE_URL="https://api.zaits.net"
# Set environment
ENVIRONMENT="test" # or "prod"
if [ "$ENVIRONMENT" = "prod" ]; then
API_KEY=$API_KEY_PROD
echo "๐ Using production environment"
else
API_KEY=$API_KEY_TEST
echo "๐งช Using test environment"
fi
export API_KEY
export BASE_URL#!/bin/bash
# main_script.sh
# Load configuration
source ./config.sh
# Use the configured API key
curl -X GET "$BASE_URL/v1/usage/summary" \
-H "Authorization: Bearer $API_KEY"Webhook Testing
# Test webhook endpoint
curl -X POST https://your-app.com/webhooks/zaits \
-H "Content-Type: application/json" \
-H "X-Zaits-Signature: sha256=your_signature" \
-d '{
"event": "document.signed",
"data": {
"document_id": "doc_123",
"status": "completed",
"signer": {
"name": "John Doe",
"email": "[email protected]"
}
},
"timestamp": "2024-01-15T10:30:00Z"
}'Performance Testing
#!/bin/bash
# Load test with multiple concurrent requests
API_KEY="your_api_key_here"
CONCURRENCY=5
TOTAL_REQUESTS=20
echo "๐ Starting load test with $CONCURRENCY concurrent requests..."
# Create temporary directory for results
mkdir -p load_test_results
# Function to make a single request
make_request() {
local request_id=$1
local start_time=$(date +%s.%N)
response=$(curl -s -w "\n%{http_code}\n%{time_total}" \
-X GET https://api.zaits.net/v1/usage/summary \
-H "Authorization: Bearer $API_KEY")
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc)
local http_code=$(echo "$response" | tail -n2 | head -n1)
local time_total=$(echo "$response" | tail -n1)
echo "Request $request_id: $http_code (${duration}s)" >> load_test_results/summary.txt
}
# Run concurrent requests
for i in $(seq 1 $TOTAL_REQUESTS); do
make_request $i &
# Limit concurrency
if (( i % CONCURRENCY == 0 )); then
wait
fi
done
wait # Wait for remaining requests
echo "โ
Load test complete. Results in load_test_results/summary.txt"
# Calculate statistics
success_count=$(grep -c "200" load_test_results/summary.txt)
error_count=$((TOTAL_REQUESTS - success_count))
echo "๐ Results:"
echo " Total requests: $TOTAL_REQUESTS"
echo " Successful: $success_count"
echo " Errors: $error_count"
echo " Success rate: $(echo "scale=2; $success_count * 100 / $TOTAL_REQUESTS" | bc)%"Next: Integration Patterns
Last updated