Code Examples
Real-world examples and sample code to get you started with PTKD API integration quickly.
API Integration Examples
Copy and adapt these examples for your preferred programming language
JavaScript/Node.js
Upload and scan an app using Node.js
const FormData = require('form-data');
const fs = require('fs');
const axios = require('axios');
async function scanApp(filePath, apiKey) {
const form = new FormData();
form.append('file', fs.createReadStream(filePath));
form.append('scan_type', 'full');
try {
const response = await axios.post('https://api.ptkd.dev/v1/scan', form, {
headers: {
'Authorization': `Bearer ${apiKey}`,
...form.getHeaders()
}
});
console.log('Scan started:', response.data);
return response.data.scan_id;
} catch (error) {
console.error('Scan failed:', error.response.data);
}
}
// Usage
scanApp('./app-release.apk', 'your-api-key-here');Python
Upload and scan an app using Python requests
import requests
import time
def scan_app(file_path, api_key):
"""Upload and scan an app, wait for results"""
# Upload and start scan
with open(file_path, 'rb') as f:
files = {'file': f}
data = {'scan_type': 'full'}
headers = {'Authorization': f'Bearer {api_key}'}
response = requests.post(
'https://api.ptkd.dev/v1/scan',
files=files,
data=data,
headers=headers
)
if response.status_code != 200:
print(f"Error: {response.json()}")
return None
scan_id = response.json()['scan_id']
print(f"Scan started: {scan_id}")
# Poll for results
while True:
response = requests.get(
f'https://api.ptkd.dev/v1/scan/{scan_id}',
headers=headers
)
scan_data = response.json()
status = scan_data['status']
if status == 'completed':
print("Scan completed!")
return scan_data['results']
elif status == 'failed':
print("Scan failed!")
return None
else:
print(f"Status: {status}")
time.sleep(30) # Wait 30 seconds before checking again
# Usage
results = scan_app('./app-release.apk', 'your-api-key-here')
if results:
print(f"Found {len(results['vulnerabilities'])} vulnerabilities")cURL
Simple command-line scanning with cURL
#!/bin/bash
API_KEY="your-api-key-here"
APP_PATH="./app-release.apk"
# Start scan
echo "Starting scan..."
SCAN_RESPONSE=$(curl -s -X POST https://api.ptkd.dev/v1/scan \
-H "Authorization: Bearer $API_KEY" \
-F "file=@$APP_PATH" \
-F "scan_type=full")
SCAN_ID=$(echo $SCAN_RESPONSE | jq -r '.scan_id')
echo "Scan ID: $SCAN_ID"
# Poll for results
while true; do
SCAN_STATUS=$(curl -s -H "Authorization: Bearer $API_KEY" \
https://api.ptkd.dev/v1/scan/$SCAN_ID)
STATUS=$(echo $SCAN_STATUS | jq -r '.status')
echo "Status: $STATUS"
if [ "$STATUS" = "completed" ]; then
echo "Scan completed!"
echo $SCAN_STATUS | jq '.results'
break
elif [ "$STATUS" = "failed" ]; then
echo "Scan failed!"
break
fi
sleep 30
doneGitHub Action
Integrate PTKD scanning into GitHub workflows
name: Mobile Security Scan
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Build APK
run: |
chmod +x ./gradlew
./gradlew assembleRelease
- name: PTKD Security Scan
uses: ptkd/github-action@v1
with:
api-key: ${{ secrets.PTKD_API_KEY }}
app-path: app/build/outputs/apk/release/app-release.apk
scan-type: full
fail-on-high: true
- name: Upload scan results
uses: actions/upload-artifact@v3
if: always()
with:
name: ptkd-security-report
path: ptkd-report.jsonPlatform Integrations
Ready-to-use integrations for popular mobile development platforms
FlutterFlow
AvailableAutomate security scanning for FlutterFlow exports
React Native
AvailableSecurity scanning for React Native applications
Flutter
AvailableNative Flutter app security analysis
Cordova/PhoneGap
BetaHybrid app security scanning
Sample Projects
Complete example projects you can clone and customize
Security Dashboard
React app showing security metrics and trends
CLI Tool
Command-line tool for batch scanning apps
Slack Bot
Slack bot for triggering scans and getting results
Video Tutorials
Step-by-step video guides for common integration scenarios
API Quickstart
CI/CD Integration
Custom Webhooks
FlutterFlow Setup
Advanced Filtering
Security Dashboard
Need a Custom Example?
Can't find what you're looking for? We'll create a custom example for your use case.