WhatsApp Cloud API - Phone Number Setup Guide
WhatsApp Cloud API - Phone Number Setup Guide
Guide for registering a new WhatsApp Business phone number with Cloud API.
Overview
| Phase | Who | What |
|---|---|---|
| 1. Prerequisites | Human/Comet | Meta Business verification, app setup |
| 2. Add Number | Human | Add phone number in Meta console |
| 3. Get Credentials | Human/Comet | Copy IDs and generate token |
| 4. Register | AI (CLI) | API call with certificate |
| 5. Webhook Setup | Human/Comet + AI | Configure webhook and subscribe WABA |
AI Agent Notes (Comet / browser agents):
- Do NOT read tokens, secrets, or IDs from screenshots. You WILL get them wrong.
- Instead, tell the human exactly what button to click to copy-paste the value.
- Tokens are ~200 characters. If yours is shorter, it’s truncated.
- The App must be in the SAME business portfolio as the phone number’s WABA. If the number is in Business A but your app is in Business B, system users in Business A won’t see your app when generating tokens. Create the app under Business A instead.
Phase 1: Prerequisites (Human/Comet)
1.1 Meta Business Account
- Go to Meta Business Suite
- Ensure your business is verified (required for production)
1.2 Meta App with WhatsApp
- Go to Meta for Developers
- Create app or use existing one with WhatsApp product enabled
- IMPORTANT: Select the business portfolio that OWNS the phone number/WABA
- Note your App ID and App Secret
1.3 Business Portfolio Check
Before proceeding, verify:
- The phone number is in WABA under Business X
- The app is created under Business X (same one)
- If not, create a new app under the correct business
Phase 2: Add Phone Number (Human)
2.1 Add the Number
- Go to WhatsApp Manager
- Click Add Phone Number
- Enter phone number (must NOT be linked to any WhatsApp account)
- Choose verification method: SMS or Voice call
- Enter the verification code
2.2 Set Display Name
- Enter your business display name
- Wait for approval (usually instant for compliant names)
2.3 Download Certificate
After display name is approved:
- Go to your phone number settings in WhatsApp Manager
- Find the Certificate section
- Copy the base64-encoded certificate string
It looks like this:
CmUKIQik06fWvoL2AhIGZW50OndhIghCaWxpbyBBSVD7/7nLBhpA...
Phase 3: Get Credentials (Human/Comet)
Comet note: For each value below, tell the human exactly which button to click to copy. Do NOT attempt to OCR values from screenshots.
3.1 Get Phone Number ID
- Go to Meta for Developers → your app
- WhatsApp → API Setup
- In the “From” dropdown, select the target phone number
- Copy the Phone Number ID shown below the dropdown
3.2 Get App Secret
- Go to your app’s Settings → Basic
- Find “App secret”, click “Show” (will ask for Facebook password)
- Copy the App Secret (32 hex characters)
3.3 Generate Permanent Access Token
- Go to Business Settings > System Users
- Create a new System User (or use existing):
- Name: descriptive (e.g., “Notaria Bot”)
- Role: Admin
- Add Assets to the System User:
- Apps → select your app → Full Control
- WhatsApp Accounts → select the WABA → Full Control
- Click Generate New Token:
- Select your app
- Token expiration: Never
- Enable permissions:
whatsapp_business_messagingwhatsapp_business_management
- Copy the token (starts with
EAA..., ~200 characters)
Comet note: The token is LONG (~200 chars). If you read it from a screenshot you WILL truncate it. Tell the human to click the copy button or manually select-all and copy from the text field.
3.4 Get WABA ID
- Go to WhatsApp Manager
- Look at the URL:
?asset_id=XXXXXXXXXX← this is your WABA ID - Or find it in Account tools → Phone numbers
3.5 Output Format
Collect all values in this format:
WHATSAPP_APP_ID=your_app_id
WHATSAPP_APP_SECRET=your_app_secret
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
WHATSAPP_ACCESS_TOKEN=your_permanent_token
WHATSAPP_VERIFY_TOKEN=your_custom_verify_token
WABA_ID=your_waba_id
Phase 4: Register via API (AI - CLI agent)
Once you have all credentials, tell the AI:
“Register my WhatsApp number. Certificate: [paste certificate]“
What the AI does:
Step 1: Verify token works
curl -s "https://graph.facebook.com/v21.0/${PHONE_NUMBER_ID}?fields=display_phone_number,verified_name,status" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Expected: Status should be PENDING
Step 2: Register with certificate
curl -s -X POST "https://graph.facebook.com/v21.0/${PHONE_NUMBER_ID}/register" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"messaging_product": "whatsapp",
"pin": "123456",
"certificate": "YOUR_CERTIFICATE_HERE"
}'
Expected: {"success": true}
Step 3: Verify registration
curl -s "https://graph.facebook.com/v21.0/${PHONE_NUMBER_ID}?fields=display_phone_number,verified_name,status,messaging_limit_tier" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Expected: Status should be CONNECTED
Phase 5: Webhook Setup (CRITICAL)
5.1 Configure Webhook URL (Human/Comet)
- Go to Meta for Developers → your app
- WhatsApp → Configuration
- In Webhook section, click Edit
- Enter:
- Callback URL:
https://your-domain.com/webhook(your public server URL) - Verify Token: same as
WHATSAPP_VERIFY_TOKENin .env
- Callback URL:
- Click Verify and Save
5.2 Subscribe to Messages Field (Human/Comet)
- In the same Configuration page
- Under Webhook fields, click Manage
- Enable (subscribe) the
messagesfield - Click Done
5.3 Enable Live Mode (Human/Comet)
- Go to App Settings → Basic
- Add Privacy Policy URL (required for Live mode)
- Toggle App Mode from “Development” to “Live”
5.4 Subscribe App to WABA (AI) - CRITICAL!
This step is often missed and causes webhooks to not arrive.
curl -s -X POST "https://graph.facebook.com/v21.0/${WABA_ID}/subscribed_apps" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Expected: {"success": true}
Verify subscription:
curl -s "https://graph.facebook.com/v21.0/${WABA_ID}/subscribed_apps" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
Should show your app in the list.
5.5 Test Webhook
- In Meta Dashboard, go to WhatsApp → Configuration → Webhook
- Click Test next to the
messagesfield - Click Send to My Server
- Check your server logs for the incoming webhook
Quick Reference
What to give the CLI AI:
- Phone Number ID: from API Setup
- Certificate: base64 string from WhatsApp Manager
- WABA ID: from WhatsApp Manager URL
- All
.envcredentials confirmed
PIN
The AI will set PIN to 123456 by default. This is your WhatsApp 2-step verification PIN. Remember it or change it later in WhatsApp Manager.
Troubleshooting
Error: “Malformed access token”
- Token is truncated (common when AI reads from screenshot)
- Solution: Copy the FULL token from System Users page (~200 characters)
Error: “Object does not exist or missing permissions”
- Token doesn’t have access to this phone number
- Common cause: App is in Business A, phone number WABA is in Business B
- Solution: Create app under the same business as the WABA, or generate token from System User that has access to both
Error: “Invalid certificate”
- Certificate expired or wrong number
- Solution: Download fresh certificate from WhatsApp Manager
Status stuck on PENDING
- Registration API call not made
- Solution: Run the register API call with certificate
Webhooks not arriving (Test works, real messages don’t)
This is the most common issue!
- Check App Mode: Must be “Live”, not “Development”
- Check WABA subscription: Run the subscribe API call:
curl -X POST "https://graph.facebook.com/v21.0/${WABA_ID}/subscribed_apps" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" - Check App Secret: The
WHATSAPP_WEBHOOK_SECRETmust match the App Secret from the correct app
Invalid webhook signature (403 error)
- The
WHATSAPP_WEBHOOK_SECRETdoesn’t match the App Secret - Verify which app your token belongs to:
curl "https://graph.facebook.com/v21.0/debug_token?input_token=${ACCESS_TOKEN}" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" - Use the App Secret from THAT app (shown in
app_idfield)
Business portfolio mismatch
- Symptom: System User can’t see your app when generating tokens
- Cause: App is under a different business portfolio than the WABA
- Solution: Create app under the business that owns the WABA
Post-Registration
After CONNECTED status and webhook working:
- Test sending a message (to your own number first)
- Test receiving a message (reply and check logs)
- Create message templates for business-initiated conversations
Messaging Limits
- Start: TIER_250 (250 conversations/24h)
- Increases automatically with quality usage
- Tiers: 250 → 1K → 10K → 100K → unlimited
Environment Variables Reference
# Required for WhatsApp integration
WHATSAPP_PHONE_NUMBER_ID=922407610962121 # From API Setup
WHATSAPP_ACCESS_TOKEN=EAA... # Permanent token from System User
WHATSAPP_VERIFY_TOKEN=YourCustomToken # For webhook verification
WHATSAPP_APP_SECRET=abc123... # From App Settings > Basic
WHATSAPP_APP_ID=1587604912547962 # From App Settings > Basic
WHATSAPP_WEBHOOK_SECRET=abc123... # Same as APP_SECRET
WABA_ID=370807332792746 # From WhatsApp Manager URL