WhatsApp API in a Flutter App: What to Call From the App and What Not To

Using the WhatsApp API in a Flutter app: open chats with wa.me and url_launcher, keep the Cloud API token on a server, and send OTPs and updates safely.

Illustration: a mobile app screen with a WhatsApp button, a server in the middle and a phone receiving an order update (sample data)

A Flutter app should never call the WhatsApp Cloud API itself. From the app, open chats with a wa.me link through url_launcher; for anything the business sends (OTPs, order updates, replies), call your own backend and let it call Meta. The reason is the access token: whatever you compile into an app can be taken out of it.

This guide draws that line clearly. It shows the Dart for opening a WhatsApp chat, the shape of the backend endpoint your app should call, how a WhatsApp OTP login fits a Flutter app, and which packages to leave alone. It uses Meta’s official Cloud API only, on Graph API v27.0, the latest version in Meta’s changelog (4 November 2026).

Key takeaways

  • App side: wa.me links with url_launcher. No token, no Meta account, works on Android, iOS and web.
  • Server side: every Cloud API call, the access token, the app secret and the webhook.
  • Flutter’s own docs call storing secrets in an app a poor security practice, and say obfuscation doesn’t stop reverse engineering.
  • Your backend should decide who gets a message and which template, not accept them from the app.
  • A WhatsApp OTP works in Flutter with the copy code button and no native code. One-tap autofill is Android only and needs a native handshake.
  • Packages that log in like WhatsApp Web aren’t the official API and can get a business number banned.

Can a Flutter app call the WhatsApp API directly?

Technically yes: the Cloud API is plain HTTPS, and Dart’s http package can POST to graph.facebook.com like anything else. You still shouldn’t, because every call needs an access token that can send messages as your business. So split the work like this:

JobWhere it runsHow
Let a user open a chat with your businessIn the appA wa.me link opened with url_launcher
Let a user share text with their own contactsIn the appA wa.me/?text= link; they pick the contact
Send an OTP, order update or reminderYour backendA template message through the Cloud API
Reply to a customer inside the 24-hour windowYour backendA text or media message through the Cloud API
Receive replies and delivery statusesYour backendA webhook endpoint Meta calls
Hold the access token and app secretYour backend onlyEnvironment variables or a secrets manager

The two halves do different things. A wa.me link makes the user start or continue a chat from their own WhatsApp. The Cloud API makes the business number send a message. An app usually needs both.

Why the access token can’t ship inside the app

An app package is a file on someone else’s phone. A token in Dart source, in an asset file or passed in at build time ends up inside that file, and so does one fetched from a remote config service once the app has it.

  • Meta’s rule. Its access tokens guide says: “Never hard-code app access tokens into client-side code or app binaries”, and that calls using the app secret must be made from server-side code only. A WhatsApp system-user token deserves the same care: it’s long-lived and represents an automated service.
  • Flutter’s rule. The Flutter docs say it’s a poor security practice to store secrets in an app, and that obfuscating your Dart code only renames symbols. It doesn’t encrypt resources or protect against reverse engineering.
  • Flutter web is no exception. The compiled app is downloaded to the browser, so anything in it is readable there too.
  • What a leaked token costs. Whoever has it can send messages from your number until you revoke it. Template messages they send are charged to you, and blocks and reports from the people who receive them count against your number’s quality rating.

Open a WhatsApp chat from Flutter with url_launcher

This is the part that belongs in the app. WhatsApp’s click to chat format is https://wa.me/<number>, with the number in full international format and no plus sign, zeros, brackets or dashes, and an optional ?text= with a URL-encoded message. Add url_launcher to pubspec.yaml, import package:url_launcher/url_launcher.dart, and:

LineDart
1Future<void> openWhatsApp(String message) async {
2final uri = Uri.parse("https://wa.me/919800000000?text=" + Uri.encodeComponent(message));
3try {
4final ok = await launchUrl(uri, mode: LaunchMode.externalApplication);
5if (!ok) showFallback();
6} on PlatformException { showFallback(); }
7}
  • LaunchMode.externalApplication hands the link to the operating system instead of opening it in an in-app web view, so WhatsApp can take it if it’s installed.
  • Handle both failures. launchUrl returns false or throws a PlatformException, depending on what went wrong. PlatformException comes from package:flutter/services.dart.
  • showFallback() is yours to write, for the rare case where the link can’t be opened at all: show the number as text or offer a phone call. Without WhatsApp installed, the link opens WhatsApp’s web page in the browser instead.
  • Skip canLaunchUrl if you can. It returns false in most cases on Android 11 and later unless the scheme is declared in a <queries> element in AndroidManifest.xml, and on iOS it needs LSApplicationQueriesSchemes in Info.plist. The package’s own advice is to call launchUrl directly and handle failure.
  • Give the message context. “Hi, I need help with order ORD-1042” tells your team who is writing and why. The user can edit it, and nothing is sent until they tap send.

Once the user sends that message, the 24-hour customer service window opens, so your side can answer with free-form messages. The link format, QR codes and encoding rules are covered in how to create a WhatsApp link and QR code, and our free WhatsApp link generator builds one to test with.

Send messages through your own backend

For messages the business sends, the app calls an endpoint you own, signed in as the user. Your server then calls Meta. The request should describe what happened in the app, not what to send on WhatsApp:

LineDart
1final res = await http.post(
2Uri.parse("https://api.example.com/orders/1042/confirm"),
3headers: {"Authorization": "Bearer $sessionToken", "Content-Type": "application/json"},
4body: jsonEncode({"notify": "whatsapp"}),
5);
6if (res.statusCode != 200) throw Exception("Could not confirm the order");

Here http is import 'package:http/http.dart' as http;, jsonEncode comes from dart:convert, and sessionToken is the signed-in user’s own token from your login system, never Meta’s. On Android, the app needs the INTERNET permission in AndroidManifest.xml. On the server, the endpoint should:

  1. Check the user’s session and that order 1042 belongs to them.
  2. Look up the phone number in your own database. Don’t take a to number from the request, or the endpoint becomes a way to message anyone.
  3. Check opt-in. Meta only lets you message WhatsApp users who have opted in to hear from you; see WhatsApp opt-in.
  4. Pick the template itself. The app shouldn’t send a template name or free text for the server to pass on.
  5. Rate-limit per user, so a loop or a tampered client can’t run up your bill.
  6. Call the Cloud API: POST https://graph.facebook.com/v27.0/<PHONE_NUMBER_ID>/messages with the Bearer token, and store the message ID that comes back.

The server can be written in anything, including Dart. We have working send helpers, error handling and signed webhooks for Node.js, Python, PHP, Java, C# and Go, and the template JSON is in how to send a WhatsApp template message with the API. To try the calls before writing a server, use the curl reference.

WhatsApp OTP login in a Flutter app

Sign-in codes are the commonest reason a Flutter team looks for a WhatsApp API. They go out as authentication templates, and the flow never puts Meta’s token near the app:

  1. The app sends the phone number to your backend, for example POST /auth/otp/start.
  2. The backend creates the code, stores it with an expiry, and sends your authentication template. Meta allows a code of up to 15 characters, and it must appear twice in the request: once in the body parameter and once in the button parameter.
  3. The user opens WhatsApp, taps Copy code, and comes back to your app.
  4. The app sends the pasted code to POST /auth/otp/verify. The backend checks it and returns a session.

That works on every phone with no native code. The faster options need more:

ButtonPhonesWhat your Flutter app needs
Copy codeAllA text field to paste into
One-tap autofillAndroid onlyA native handshake with WhatsApp before each send, an activity that receives the code, and your package name and signing key hash in the template
Zero-tapAndroid onlyNative Android code with a broadcast receiver, which gets the code with no tap

Meta publishes an OTP SDK for Android to do the handshake, and its pages describe no Flutter package. In a Flutter app that means a small piece of Kotlin or Java in the android folder, reached from Dart through a platform channel. If any of WhatsApp’s checks fails, or the user isn’t on Android, the message shows a copy code button instead, so build the paste field first and add autofill afterwards. On iOS 26 and later, the keyboard suggests the code with no work from you.

Template rules, expiry settings and pricing are in WhatsApp OTP: authentication templates explained.

Show replies and delivery status in the app

A send that Meta accepts returns a message ID. Meta’s page is clear that this means the request was accepted, not that the message was delivered. Sent, delivered, read and failed statuses, and anything the customer writes back, are pushed to a webhook: a public HTTPS endpoint with a valid certificate. A phone app can’t be that endpoint.

  1. Your backend receives the webhook, checks the X-Hub-Signature-256 signature with your app secret, and returns 200 quickly.
  2. It stores the event against the message ID or the customer.
  3. It tells the app through your own channel: a push notification, a WebSocket, or the next time the app fetches from your API.

So an in-app “Delivered” tick or a support chat screen reads from your server, never from Meta. Payloads and retries are in WhatsApp Cloud API webhooks.

Flutter WhatsApp packages to avoid

Search pub.dev or GitHub for WhatsApp and Flutter and you’ll find three kinds of package. Read the source before adding one.

KindWhat it doesUse it?
Link openersBuild a wa.me link and open itHarmless, but url_launcher already does this in a few lines
Cloud API wrappersCall graph.facebook.com with a token you pass in from DartOnly in server-side Dart. In an app, it puts the token in the binary
WhatsApp Web or “no API needed” toolsLog in like a linked device, often with a QR code, and automate a personal or Business app accountNo. It isn’t Meta’s Business API

WhatsApp’s Help Center says unofficial apps break its Terms of Service and that an account using them might be temporarily or permanently banned. You’d also have no approved templates and no webhooks from Meta. The full comparison is in official vs unofficial WhatsApp APIs.

Flutter with Automate AI

If you’d rather not host Meta’s webhooks or build an inbox, Automate AI connects your number and handles them. Chats that start from your app’s wa.me button land in a shared inbox for your team, and approved templates go out as campaigns or from chatbots built without code.

For messages your app triggers, your backend can call Automate AI’s REST API, which has endpoints for contacts, messages, templates, campaigns and automations, and webhooks for events such as message received and status updates. The same rule applies: its API key goes in an Authorization: Bearer header from your server, never from the Flutter app. A new key is shown once, when you create it. The API and webhooks are included on the AI + Automation Plan and Series 4; see the WhatsApp Business API page and pricing.

Frequently asked questions

Can I use the WhatsApp API directly in a Flutter app?

You can make the HTTPS call from Dart, but you shouldn’t. The call needs an access token, and anything compiled into an app can be extracted. Call your own backend from the app and let the backend call Meta’s Cloud API.

How do I open WhatsApp from a Flutter app?

Build a link such as https://wa.me/919800000000?text=..., with the message passed through Uri.encodeComponent, and open it with launchUrl from the url_launcher package using LaunchMode.externalApplication.

Is there an official WhatsApp Flutter SDK?

Meta’s Cloud API pages describe HTTP requests, and its OTP SDK is for Android. They name no Flutter package. For opening chats, url_launcher from the Flutter team is enough.

Where should the WhatsApp access token be stored?

On your server, in environment variables or a secrets manager. Never in Dart code, an asset, a build-time value or remote config that the app downloads.

How do I send a WhatsApp OTP from a Flutter app?

The app sends the phone number to your backend. The backend creates the code and sends an authentication template through the Cloud API. The user copies the code from WhatsApp into your app, and the app sends it back to your backend to verify.

Why does canLaunchUrl return false for a WhatsApp link?

On Android 11 and later it returns false in most cases unless the scheme is listed in a <queries> element in the manifest, and iOS needs LSApplicationQueriesSchemes. The package recommends calling launchUrl directly and handling failure.

Can a Flutter app receive WhatsApp messages?

Not from Meta directly. Incoming messages go to a webhook on a public HTTPS server. Your backend receives them and passes them to the app by push notification, WebSocket or your own API.

Sources

  1. Meta: Access tokens guide (client-side code and app secrets)
  2. Meta: WhatsApp access tokens
  3. Meta: Send messages
  4. Meta: One-tap autofill authentication templates
  5. Flutter: Obfuscate Dart code
  6. pub.dev: url_launcher
  7. WhatsApp Help Center: About unofficial WhatsApp apps
  8. WhatsApp Help Center: How to use click to chat

WhatsApp rules and prices change. We check these guides against Meta’s documentation, but always confirm current terms with Meta before you rely on them. Questions? Message us on WhatsApp at +91 836 977 8812.