Development Guide
Prerequisites
- Python 3.9 or higher
- Apify account and API token
- Google Cloud Platform project with BigQuery enabled
- Access to the appropriate environment (dev/staging/production)
Setup on Local
1. Install Dependencies
pip install -r requirements.txt
2. Set Environment Variables
export APIFY_TOKEN="your_apify_token"
export GCP_PROJECT_ID="your_project_id"
export BRAND_INTERACTIONS_WEBHOOK_URL="http://localhost:8080/webhook/apify"
export ENVIRONMENT="dev" # Options: dev, staging, production
3. Run the API Server
uvicorn src.linkedin_interactions_pipelines.main:app --host 0.0.0.0 --port 8080
4. Test the Endpoint
curl -X POST http://localhost:8080/apify/linkedin/interactions \
-H "Content-Type: application/json" \
-d '{
"user_company_id": "12345678",
"targets": [{"linkedin_handle": "microsoft", "entity": "COMPANY"}]
}'
Development Workflow
Feature Development Process
-
Create Feature Branch
git checkout develop git pull origin develop git checkout -b feature/your-feature-name -
Develop and Test Locally
- Make your changes
- Test locally using the dev environment
-
Run unit tests (if available)
-
Merge to Develop
git checkout develop git merge feature/your-feature-name git push origin develop - This automatically deploys to the Dev environment
-
Test in the Dev environment
-
Promote to Staging
git checkout staging git merge develop git push origin staging - This automatically deploys to the Staging environment
-
Perform comprehensive testing
-
Deploy to Production
- Open a Pull Request from
stagingtomain - Get PR reviewed and approved
- Merge to
main - This automatically deploys to Production
Environment Configuration
Dev Environment
- Purpose: Local and development testing
- API URL:
https://brand-interactions-pipeline-dev-691864719497.us-central1.run.app - Tracker Table:
linkedin.ApifyInteractionsTrackerTableDev - Branch:
develop
Staging Environment
- Purpose: Pre-production validation
- API URL:
https://brand-interactions-pipeline-staging-691864719497.us-central1.run.app - Tracker Table:
linkedin.ApifyInteractionsTrackerTableStaging - Branch:
staging
Production Environment
- Purpose: Live production use
- API URL:
https://brand-interactions-pipeline-691864719497.us-central1.run.app - Tracker Table:
linkedin.ApifyInteractionsTrackerTable - Branch:
main
Testing Tips
Testing API Endpoints
-
Health Check
curl https://brand-interactions-pipeline-dev-691864719497.us-central1.run.app/health -
Trigger Scraping Job
curl -X POST https://brand-interactions-pipeline-dev-691864719497.us-central1.run.app/apify/linkedin/interactions \ -H "Content-Type: application/json" \ -d '{ "user_company_id": "test123", "targets": [{"linkedin_handle": "microsoft", "entity": "COMPANY"}], "max_posts": 5 }' -
Check Job Status in BigQuery
SELECT * FROM `linkedin.ApifyInteractionsTrackerTableDev` WHERE user_company_id = 'test123' ORDER BY created_at DESC LIMIT 10;
Common Issues
- Webhook not receiving callbacks
- Check that
BRAND_INTERACTIONS_WEBHOOK_URLis publicly accessible -
Verify Apify actor configuration includes webhook URL
-
BigQuery permission errors
- Ensure service account has proper BigQuery roles
-
Check
GCP_PROJECT_IDis correct -
Apify job fails
- Check Apify token is valid
- Verify LinkedIn handle format is correct
- Check Apify actor logs for specific errors
Code Structure
src/linkedin_interactions_pipelines/
├── main.py # FastAPI application and endpoints
├── apify_client.py # Apify API client wrapper
├── bigquery_client.py # BigQuery operations
├── models.py # Pydantic request/response models
├── webhook_handler.py # Webhook callback processing
└── polling_job.py # Fallback polling job
Best Practices
- Always test in Dev first before promoting to Staging or Production
- Use small test datasets (e.g.,
max_posts: 5) during development - Monitor tracker tables to verify jobs are completing successfully
- Check Apify logs if scraping fails
- Validate request payloads match the API schema before sending