# Set up your Meta app and token for WhatsApp Business Cloud

A click-by-click walkthrough of the Meta side of WhatsApp Business Cloud: which Meta account is which, where each of the five values PiGi asks for lives, how to give a system user the right access so its token works, how to point Meta's webhook at PiGi, and what every error you can hit along the way means.

Source: https://help.pigi.io/guides/integrations/communication/whatsapp-business-meta-setup

## Quick answers

**What do I need from Meta to connect WhatsApp Business Cloud to PiGi?**
Five values: **Access token** (a permanent system-user token), **Phone number ID**,
**WhatsApp Business Account ID**, **App secret**, and a **Webhook verify token** that you
make up yourself. You enter all five on the WhatsApp Business Cloud integration under
**Company → Settings → Integrations**.

**Meta shows a "Messaging account", a "WhatsApp account" and a "WhatsApp Business App". Which is which?**
In Meta's current Business settings, **Messaging accounts** are WhatsApp Business
Accounts: their ID is the **WhatsApp Business Account ID** PiGi asks for. **WhatsApp
accounts** are individual phone numbers. An entry labelled **WhatsApp Business App** is a
number running in the WhatsApp Business app on a phone; it is not the Cloud API account.
The **business portfolio** ID (`business_id=` in the address bar) is none of these and is
not entered in PiGi.

**Where do I find the WhatsApp Business Account ID?**
In business.facebook.com → **Settings → Business assets → Messaging accounts**, click your
account: the ID is shown under its name. It is also the number after `asset_id=` in the
WhatsApp Manager address bar, and it is listed on your Meta app's **API Setup** /
**Production setup** page under the sending number. Do not use the `business_id=` number.

**Where do I find the Phone number ID?**
In your Meta app, open **Use cases → WhatsApp → Customize → API Setup** (or **Step 2.
Production setup**), choose your number in **From**, and the Phone number ID is shown
underneath. It is a long number, not the phone number itself. You can also list it with
the token: see "Check a token from the command line" below.

**Where do I find the App secret?**
developers.facebook.com → your app → **App settings → Basic** → **App secret** → **Show**.
It is 32 letters and digits. The **App ID** on the same page is all digits and is not the
secret.

**What callback URL and verify token do I give Meta?**
Callback URL: `https://api.pigi.io/api/v1/notifications/public/webhooks/whatsapp/`, with
the trailing slash. Verify token: any long random text, entered identically in PiGi's
**Webhook verify token** field and in Meta. Save it in PiGi, with the integration switched
on, before you press **Verify and save** in Meta.

**Should my system user be Admin or Employee?**
Either works. An **Admin** system user can reach every asset in the business portfolio.
An **Employee** system user can reach only what you assign, so assign it the app, the
**Messaging account** and the **WhatsApp account** (phone number), each with full control.
Meta does not let a person who joined the business portfolio less than 7 days ago make a
system user Admin; use Employee and assign the assets instead.

**I gave the system user more access. Why does the token still fail?**
A token keeps the access the system user had when the token was generated. After changing
assigned assets, press **Generate token** again and paste the new token into PiGi.

**Should I attach a client certificate to webhook requests?**
No. Leave it off. PiGi checks each webhook call against your **App secret** instead.

**Meta says my app is unpublished. Does that matter?**
Yes, for incoming messages. While the app is unpublished Meta only delivers the test
webhooks you send from the app dashboard: real customer replies, delivery receipts and
opt-outs do not reach PiGi. You can still verify the webhook and send messages. Publish the
app from **Publish** in the app's left menu once **App settings → Basic** has a privacy
policy URL and category.

**Is a +1 555 number a test number?**
Not always. Meta's free test numbers look like +1 555-xxx-xxxx and can only message up to
five numbers you approve, but Meta also issues real numbers in that range. Check WhatsApp
Manager → **Account tools → Phone numbers**: a real number shows **Connected** with a
messaging limit.

**Can I send a test WhatsApp message from PiGi?**
Not from the integration itself. Once a WhatsApp notification has an approved template
picked, use **Send test** on that notification. Before that, send Meta's built-in
`hello_world` template from the command line (below) to prove the number and token work.

## What this is

Connecting WhatsApp Business Cloud is mostly work inside Meta: an app, a WhatsApp Business
Account with a number, a system user whose token can manage it, and a webhook back to
PiGi. For templates and costs, see **Send notifications with WhatsApp Business Cloud**.

## Meta's names for things

Meta's names, mapped:

| Meta calls it | What it is | Used in PiGi |
|---|---|---|
| Business portfolio | Your company in Meta (`business_id=` in URLs) | No |
| App (e.g. "Your School PiGi App") | The developer app at developers.facebook.com | Its **App secret** |
| Messaging account | The WhatsApp Business Account (WABA) | Its ID is the **WhatsApp Business Account ID** |
| WhatsApp account | One phone number inside a Messaging account | Its **Phone number ID** |
| WhatsApp Business App | A number used in the phone app, not the Cloud API | No |
| System user | A non-human user that owns the token | Its token is the **Access token** |

## Before you start

- The **admin** role in PiGi.
- Admin access to your Meta business portfolio at business.facebook.com.
- A phone number for WhatsApp that is not logged into the WhatsApp or WhatsApp Business
  app on a phone.
- A payment card for Meta's per-message charges.
- Your privacy policy URL, for publishing the app.

## Step 1: Create the Meta app

1. At developers.facebook.com, open **My Apps → Create app**.
2. Choose the use case **Connect with customers through WhatsApp** and link your business
   portfolio. Keep "WhatsApp", "Meta" and "Facebook" out of the app name.
3. On the app's **Dashboard**, click **Customize the Connect with customers through
   WhatsApp use case**. **Integrate with API** is a tab and is already selected.
4. Skip **Step 1. Try it out** (Meta's test number) and open **Step 2. Production
   setup**.

## Step 2: Add your number and payment method

1. In **Production setup**, create or choose your WhatsApp Business Account (Messaging
   account), set a display name that matches your business, add your number and confirm
   it with Meta's SMS or voice code.
2. In WhatsApp Manager → **Account tools → Phone numbers**, check the number shows
   **Connected**. If Meta asks for registration, set a 6-digit two-step verification PIN.
3. Add a payment method to the Messaging account (**Payment configurations** in
   WhatsApp Manager). Without one, template messages are not delivered.

## Step 3: Create the system user and its token

1. Go to business.facebook.com → **Settings → Users → System users** and press **Add**.
   Name it (for example "PiGi") and choose **Admin** or **Employee**.
2. Select the system user and press **Assign assets**. Assign all three, each with
   **Full control** (Meta may show "Full access"):
   - **Apps**: your PiGi app.
   - **Messaging accounts**: your WhatsApp Business Account (not the "WhatsApp Business
     App" entry).
   - **WhatsApp accounts**: your phone number.
3. Check the system user's **Assigned assets** tab lists the app, the Messaging account
   and the WhatsApp account.
4. Press **Generate token**. Pick your app, set expiry to **Never**, tick
   `whatsapp_business_messaging` and `whatsapp_business_management`, and generate.
5. Copy the token straight away. Meta shows it once. It starts with `EAA` and is usually
   over 180 characters.

If you assign anything later, generate a new token.

## Step 4: Collect the IDs and app secret

| PiGi field | Where in Meta |
|---|---|
| Access token | The token from Step 3 |
| Phone number ID | App → Use cases → WhatsApp → API Setup / Production setup, under the number in **From** |
| WhatsApp Business Account ID | Business settings → Business assets → **Messaging accounts** → your account, or `asset_id=` in the WhatsApp Manager URL |
| App secret | App → App settings → Basic → App secret → Show |
| Webhook verify token | Make up a long random string |

Copy each value without leading or trailing spaces or punctuation.

## Step 5: Enter the values in PiGi

1. Open **Company → Settings → Integrations** and click **WhatsApp Business Cloud**.
2. Press **Add credentials** (or **Update credentials**) and fill in all five fields.
3. Make sure the integration is switched on, then **Save**.
4. Press **Test connection**. A working setup shows **Connection works** with "Connected
   as +… (your display name). Quality: … Webhook subscribed." Test connection also
   subscribes your app to your WhatsApp Business Account's events.

## Step 6: Point Meta's webhook at PiGi

1. In the app, open **Use cases → WhatsApp → Customize → Configuration** (or **Step 2.
   Production setup → Webhooks**).
2. Callback URL: `https://api.pigi.io/api/v1/notifications/public/webhooks/whatsapp/`.
3. Verify token: the same string you saved in PiGi.
4. Leave **Attach a client certificate to Webhooks requests** off.
5. Press **Verify and save**, then under **Webhook fields** subscribe to **messages**.

## Step 7: Publish and verify your business

1. In **App settings → Basic**, fill in **Privacy policy URL**, **Category** and an app
   icon.
2. Press **Publish** in the app's left menu. Until then, real replies and delivery
   receipts do not reach PiGi.
3. Recommended: **Step 3. Business verification**. Until verified, Meta limits you to
   250 new customers a day; you can go live before it is done.

## Check a token from the command line

These commands talk to Meta only. Put your token between the single quotes, on one line.

See what a token can reach:

```
T='your-token'; curl -s "https://graph.facebook.com/v23.0/debug_token?input_token=$T&access_token=$T"
```

A good token shows `"is_valid":true`, `"expires_at":0` (never), both WhatsApp scopes, and
under each scope `"target_ids"` containing your WhatsApp Business Account ID. No
`target_ids` means the system user has not been given the Messaging account.

List the numbers on your WhatsApp Business Account (the `id` is the Phone number ID):

```
T='your-token'; curl -s "https://graph.facebook.com/v23.0/WABA_ID/phone_numbers?access_token=$T"
```

Subscribe the app to the account, which is what Test connection does:

```
T='your-token'; curl -s -X POST "https://graph.facebook.com/v23.0/WABA_ID/subscribed_apps?access_token=$T"
```

`{"success":true}` means it worked.

## Send a test message

Send Meta's built-in `hello_world` template to your own phone, writing the number in
international format without the `+` (for example `27821234567`):

```
T='your-token'; curl -s -X POST "https://graph.facebook.com/v23.0/PHONE_NUMBER_ID/messages" -H "Authorization: Bearer $T" -H "Content-Type: application/json" -d '{"messaging_product":"whatsapp","to":"27821234567","type":"template","template":{"name":"hello_world","language":{"code":"en_US"}}}'
```

A reply containing `"messages":[{"id":"wamid…"}]` and a "Hello World" message on the phone
means sending works. Then reply from the phone: once the app is published and the webhook
subscribed, the reply appears in PiGi's WhatsApp chats.

## Troubleshooting

| What you see | Cause | Fix |
|---|---|---|
| Meta: "The callback URL or verify token couldn't be validated." | PiGi has no switched-on WhatsApp Business Cloud integration with that exact verify token | Save the verify token in PiGi with the integration on, then press **Verify and save** again |
| PiGi: "Connected as … but the webhook subscription failed: Unsupported post request. Object with ID '…' does not exist, cannot be loaded due to missing permissions…" | The token can read the number but has not been given the Messaging account, or the account ID is wrong | Assign the **Messaging account** to the system user with full control, generate a new token, update PiGi. Check the ID is the Messaging account's, with no trailing full stop or space |
| PiGi: "Meta refused the token or number: …" | Wrong, expired or temporary token, or wrong Phone number ID | Generate a permanent system-user token; recheck the Phone number ID |
| PiGi: "… is not registered for the Cloud API yet" | The number is not registered for the Cloud API | Register it in WhatsApp Manager with a 6-digit PIN |
| debug_token: "Invalid OAuth access token - Cannot parse access token" | The token was cut off, wrapped or left as a placeholder in the command | Paste the whole token between single quotes on one line |
| debug_token shows no `target_ids` | The system user has no WhatsApp assets | Assign the Messaging account and WhatsApp account, then generate a new token |
| Meta: "What permissions will be granted to the app? No permissions available" | The system user is not assigned to the app | Assign the app to the system user, then generate the token |
| Meta will not let you make the system user Admin | You joined the business portfolio less than 7 days ago | Use an Employee system user with assigned assets, or ask a longer-standing admin |
| Messages send but replies never reach PiGi | App unpublished, webhook not verified, or `messages` field not subscribed | Publish the app, verify the webhook, subscribe to `messages`, then run **Test connection** |
| Template messages accepted but not delivered | No payment method on the Messaging account | Add a payment method |

## Known limitations

- PiGi has no test-message button for WhatsApp Business Cloud; use the command above or
  **Send test** on a notification with an approved template.
- Meta renames its menus often. If one named here is missing, look under **Use cases →
  WhatsApp → Customize**.

## Related

- [Send notifications with WhatsApp Business Cloud](whatsapp-business.md)
- [WhatsApp message templates to submit to Meta](whatsapp-templates.md)
