The Postalytics plugin integrates with the Postalytics API to enable sending direct mail (postcards and letters) campaigns to contacts directly from the Kizen platform. The plugin supports both development and production environments and provides a seamless workflow for selecting and sending mail campaigns to individual contacts.
The main configuration file defines:
- Authentication: Uses basic auth token authentication with API key stored as a secret
- Environments: Supports both dev and prod environments with separate API endpoints
- Dev:
https://api-dev.postalytics.com/api/v1/ - Prod:
https://api.postalytics.com/api/v1/
- Dev:
- Optional Entitlement:
postalytics_enabled- must be set to either "dev" to use Sandbox, missing entitlement defaults to "prod" - Secret Storage: API key stored as
postalytics__api_keyin integration secrets
Purpose: Allows users to send a Postalytics campaign to a single contact from the contact detail page.
Implementation (script.js):
The action performs the following workflow:
-
Environment Validation
- Checks if Postalytics is enabled for the business
- Validates environment is either "dev" or "prod"
-
Contact Field Processing
- Processes all contact fields
- Handles multi-value fields by converting them to arrays
- Validates required fields are present
-
Required Fields Validation Ensures the following fields exist on the contact:
first_namelast_namestreet_address_1citystatezipcode
-
Campaign Selection
- Fetches available campaigns from Postalytics API (
/campaigns/dripsendpoint) - Presents a dropdown prompt for user to select campaign
- Each campaign has a
nameandendpoint_id
- Fetches available campaigns from Postalytics API (
-
Field Mapping Maps Kizen contact fields to Postalytics API fields:
Kizen Field → Postalytics Field street_address_1 → address_street street_address_2 → address_street2 city → address_city state → address_state zipcode → address_zip first_name → first_name last_name → last_name email → email_address phone_mobile → mobile_phone phone_home → phone -
Special Field Processing
- Dynamic Tags: Extracts tag names/values from array
- Money Fields: Uses description or value
- Rating Fields: Uses value or name
- Multi-value Fields: Joins with comma separator
-
API Request
- Sends POST request to
/send/{campaign_endpoint_id} - Includes mapped contact data as JSON payload
- Shows success/failure toast notification
- Sends POST request to
Purpose: Enables automated sending of Postalytics campaigns to contacts through automation workflows.
Implementation (script.py):
The user must define the endpoint variable. Contact fields are prepopulated and able to be overridden.
The automation step performs the following:
-
Required Field Validation
- Validates all required address fields are present in inputs
- Required fields:
input_city,input_state,input_street1,input_zip,input_first_name,input_last_name
-
State Field Mapping
- Fetches contact field definitions from Kizen API
- Maps state field IDs to state names for proper API formatting
- Validates state value exists in field options
-
Payload Construction
- Maps input fields to Postalytics API format
- Includes optional email field if provided
-
API Request with Retry Logic
- Sends POST request to
/send/{campaign_id}endpoint - Implements automatic retry on rate limiting (429 status)
- Uses exponential backoff with up to 3 retries
- Respects
Retry-Afterheader when present
- Sends POST request to
Required Secrets:
postalytics__api_key: Base64-encoded API key for authentication
- Type: Basic Authentication
- Username: API Key (stored as secret)
- Password: Empty string
-
Get Campaigns
- Path:
/campaigns/drips - Method: GET
- Returns: List of available campaigns with
nameandendpoint_id
- Path:
-
Send Campaign
- Path:
/send/{campaign_endpoint_id} - Method: POST
- Headers:
Content-Type: application/json - Body: Contact data mapped to Postalytics fields
- Path:
All API calls go through Kizen's proxy:
/external-integrations/proxy/postalytics/{env}/{endpoint}Where {env} is either "dev" or "prod"
- Enable entitlement
postalytics_enabledwith value "dev" to use Sandbox account - Configure API key in integration secrets as
postalytics__api_key- Open Postalytics account dashboard
- Go to Connect->API Key settings
- Copy base64-encoded token (
Basic {base64_encoded_token}) from Authorization Header and paste in integration secret
The contact object (client_client) must have these fields:
- Basic address fields (street, city, state, zip)
- Name fields (first_name, last_name)
- Optional: email, phone fields
- Kizen dev sandbox credentials available in 1Password
- Create
Triggered Dripcampaigns in Postalytics dashboard
- Invalid Entitlement: Shows error if
postalytics_enabledis not set to "dev" or "prod" - Missing Required Fields: Lists all missing required fields
- No Campaigns Available: Shows toast notification
- API Failures: Displays error message with details
The automation script implements exponential backoff:
- Retries up to 3 times on 429 status
- Uses
Retry-Afterheader or exponential delay if not available
- Set up a test business with
postalytics_enabledentitlement set to "dev" - Configure API key in integration secrets
- Create test contact with all required fields
- Navigate to contact detail page
- Run "Send Campaign Mail" action
- Select campaign and confirm
-
"Postalytics entitlement is invalid"
- Solution: Add
postalytics_enabled: "dev"to business or remove to set to "prod"
- Solution: Add
-
"Required fields are missing"
- Solution: Ensure contact has all address fields populated
-
"No campaigns found"
- Solution: Create campaigns in Postalytics dashboard
-
API Authentication Failures
- Solution: Verify API key is correctly stored in secrets
- Update version in
kizen.json - Test in dev environment
- Update release branches and environments in config
- Deploy to production when ready
For issues or questions:
- Verify configuration in
kizen.json - Ensure Postalytics account is properly configured
- Contact integration team for API key or entitlement issues
- Use Kizen's secret management system
- Rotate keys periodically
- Use separate keys for dev/prod environments
- Contact data is sent to Postalytics servers
- Ensure compliance with data protection regulations
- Implement appropriate consent mechanisms
- Log minimal PII in debug messages
{
"drips": [
{
"name": "Welcome Campaign",
"endpoint_id": "abc123"
},
{
"name": "Holiday Promotion",
"endpoint_id": "def456"
}
]
}{
"send_date": "2024-12-08T10:00:00Z",
"status": "queued",
"recipient_id": "xyz789"
}