Skip to content

Installation

This guide will help you install and set up meta-cloud-api in your project.

System Requirements

Before installing, ensure your system meets these requirements:

  • Node.js: >= 18.0.0
  • Package Manager: npm, yarn, or pnpm
  • TypeScript: >= 5.0.0 (recommended)

Install the Package

Choose your preferred package manager:

Terminal window
pnpm add meta-cloud-api

TypeScript Configuration

If you’re using TypeScript, ensure your tsconfig.json includes:

{
"compilerOptions": {
"target": "ES2022",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
}
}

Environment Variables

Create a .env file in your project root:

Terminal window
# Required
CLOUD_API_ACCESS_TOKEN=your_access_token
WA_PHONE_NUMBER_ID=your_phone_number_id
# Optional
WA_BUSINESS_ACCOUNT_ID=your_business_account_id
WEBHOOK_VERIFICATION_TOKEN=your_webhook_token

Getting Your Credentials

To obtain these credentials:

  1. Access Token:

    • Go to Meta Developer Portal
    • Create a new app or select an existing one
    • Navigate to WhatsApp > API Setup
    • Copy your temporary or permanent access token
  2. Phone Number ID:

    • In the WhatsApp API Setup page
    • Find your phone number under “Phone numbers”
    • Copy the Phone Number ID
  3. Business Account ID (optional):

    • In Meta Business Suite
    • Go to Business Settings
    • Copy your WhatsApp Business Account ID
  4. Webhook Verification Token (for webhooks):

    • Create a random secure string
    • Use this when setting up webhooks in Meta Developer Portal

Verify Installation

Create a test file to verify the installation:

test.ts
import WhatsApp from 'meta-cloud-api';
const client = new WhatsApp({
accessToken: process.env.CLOUD_API_ACCESS_TOKEN!,
phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID),
businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID,
});
console.log('✓ meta-cloud-api installed successfully!');

Run the test:

Terminal window
tsx test.ts
# or
node --loader ts-node/esm test.ts

If you see the success message, you’re ready to start using meta-cloud-api!

Troubleshooting

Module not found error

If you get a “Cannot find module ‘meta-cloud-api’” error:

  1. Ensure the package is installed: pnpm list meta-cloud-api
  2. Clear your node_modules and reinstall: rm -rf node_modules && pnpm install
  3. Check your import statement matches the package name exactly

TypeScript errors

If you encounter TypeScript errors:

  1. Ensure you’re using TypeScript >= 5.0.0
  2. Enable esModuleInterop in tsconfig.json
  3. Check that moduleResolution is set to “node”

Environment variable issues

If environment variables aren’t loading:

  1. Install dotenv: pnpm add dotenv
  2. Load at app entry: import 'dotenv/config';
  3. Verify .env file is in the correct location

Support

Need help? Check out: