Guides
Getting started

Quickstart

Activate the sandbox, get a token, publish a click-to-WhatsApp campaign, approve the ad, simulate a click and read the metrics.

This guide takes a few minutes: you activate the simulator, get a token without going through the dialog, publish a campaign, ad set, creative and ad, approve the ad, simulate a click that becomes a WhatsApp message and query Insights.

Prerequisites

  • A Mimicr organization and a write API key (mk_…), created in the organization settings, "Chaves de API" tab.
  • A WhatsApp sandbox in the same organization, for click-to-WhatsApp (step 7).
  • curl, or any HTTP client, and Node 18+ if you want to use the CLI.

1. Activate the Meta Ads sandbox

In the console, open your organization at https://app.mimicr.dev, go to Meta Ads and activate it. Or use the control API:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/meta-ads/activate \
  --header 'Authorization: Bearer mk_...'

The sandbox starts with an app (its own app id and app secret) and a Business Manager with three ad accounts in BRL and timezone 25 (America/Sao_Paulo): A active, B disabled and C a client account. It also creates two Pages and three users: Ana (admin), Bruno (no_accounts) and Carla (no_business). If it is already active, the call answers 409 meta_ads_already_active.

2. Read the credentials

bash
curl --url https://api.mimicr.dev/v1/meta-ads \
  --header 'Authorization: Bearer mk_...'
json
{
  "active": true,
  "host": "https://meta-ads.mimicr.dev",
  "api_version": "v27.0",
  "accepted_versions": ["v24.0", "v25.0", "v26.0", "v27.0"],
  "app": {
    "app_id": "519118646608529",
    "app_secret": "<app_secret>",
    "app_token": "519118646608529|<app_secret>",
    "redirect_uris": [],
    "dialog_url": "https://meta-ads.mimicr.dev/v27.0/dialog/oauth",
    "token_url": "https://meta-ads.mimicr.dev/v27.0/oauth/access_token"
  },
  "business": { "id": "842989790016191", "name": "BM Minha Org" },
  "ad_accounts": [
    { "id": "act_100539998049706", "name": "Minha Org (principal)", "account_status": 1, "currency": "BRL", "timezone_id": 25, "owned": true },
    { "id": "act_100539998049707", "name": "Minha Org (desativada)", "account_status": 2, "currency": "BRL", "timezone_id": 25, "owned": true },
    { "id": "act_100539998049708", "name": "Cliente de Minha Org", "account_status": 1, "currency": "BRL", "timezone_id": 25, "owned": false }
  ],
  "pages": [
    { "id": "100539998049709", "name": "Minha Org", "whatsapp_number": null },
    { "id": "100539998049710", "name": "Minha Org Ofertas", "whatsapp_number": null }
  ],
  "whatsapp": null
}

The ids above are examples; use the ones from your sandbox. With the CLI: npx mimicr login mk_... once, then npx mimicr status meta-ads.

3. Get a token

In the real integration, the person goes through the login dialog and your server exchanges the code at /oauth/access_token (see Authentication). To test quickly, Mimicr issues a 60-day user token for the admin persona:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/meta-ads/token \
  --header 'Authorization: Bearer mk_...'
json
{
  "access_token": "EAA…",
  "token_type": "bearer",
  "expires_in": 5183944,
  "user_id": "100539998049703",
  "permissions": ["ads_read", "ads_management", "business_management", "pages_show_list", "pages_read_engagement", "pages_manage_ads", "catalog_management", "email", "leads_retrieval", "pages_manage_metadata", "whatsapp_business_management", "whatsapp_business_manage_events", "public_profile"]
}

4. Make the first call

bash
curl --url 'https://meta-ads.mimicr.dev/v27.0/me/adaccounts?fields=id,name,currency,account_status' \
  --header 'Authorization: Bearer <token>'

The token can also go as access_token in the query or in the body, as on Meta. Every response carries the facebook-api-version header.

Click-to-WhatsApp needs a Page with a WhatsApp number. Link one of the organization's WhatsApp sandboxes; the first Page gets its number:

bash
curl --request PUT \
  --url https://api.mimicr.dev/v1/meta-ads/whatsapp \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "workspace": "meu-sandbox" }'

6. Publish the campaign, ad set, creative and ad

bash
ACT=act_100539998049706
PAGE=100539998049709
H='Authorization: Bearer <token>'
B=https://meta-ads.mimicr.dev/v27.0

curl -s "$B/$ACT/campaigns" -H "$H" \
  -F name='Gás em casa' -F objective=OUTCOME_ENGAGEMENT -F status=PAUSED \
  -F special_ad_categories='[]' -F is_adset_budget_sharing_enabled=false
# {"id":"120200539998049712"}

curl -s "$B/$ACT/adsets" -H "$H" \
  -F name='Gás em casa' -F campaign_id=120200539998049712 -F status=PAUSED \
  -F billing_event=IMPRESSIONS -F optimization_goal=CONVERSATIONS \
  -F bid_strategy=LOWEST_COST_WITHOUT_CAP -F daily_budget=2000 \
  -F destination_type=WHATSAPP -F promoted_object="{\"page_id\":\"$PAGE\"}" \
  -F targeting='{"geo_locations":{"countries":["BR"]},"age_min":18,"targeting_automation":{"advantage_audience":0}}'
# {"id":"120200539998049713"}

curl -s "$B/$ACT/adcreatives" -H "$H" \
  -F name=Botijão \
  -F object_story_spec="{\"page_id\":\"$PAGE\",\"link_data\":{\"message\":\"Botijão em 30 min\",\"name\":\"Peça pelo WhatsApp\",\"picture\":\"https://cdn.example.com/botijao.jpg\",\"link\":\"https://api.whatsapp.com/send\",\"call_to_action\":{\"type\":\"WHATSAPP_MESSAGE\",\"value\":{\"app_destination\":\"WHATSAPP\"}}}}"
# {"id":"120200539998049717"}

curl -s "$B/$ACT/ads" -H "$H" \
  -F name=Botijão -F adset_id=120200539998049713 \
  -F creative='{"creative_id":"120200539998049717"}' -F status=PAUSED
# {"id":"120200539998049721"}

The ad goes into review: effective_status stays IN_PROCESS for about 5 s and then becomes PENDING_REVIEW. Details in Create a campaign.

7. Approve the ad, activate it and simulate the click

Review finishes on its own after 10 sandbox minutes. To skip the wait, play the reviewer and then activate all three levels:

bash
npx mimicr action meta-ads ad.approve ad_id=120200539998049721
for id in 120200539998049721 120200539998049713 120200539998049712; do
  curl -s "$B/$id" -H "$H" -F status=ACTIVE
done
curl -s "$B/120200539998049721?fields=effective_status" -H "$H"
# {"effective_status":"ACTIVE","id":"120200539998049721"}

Now someone clicks the ad and writes on WhatsApp:

bash
npx mimicr action meta-ads ad.click_to_whatsapp ad_id=120200539998049721 wa_id=5511999990000

The response carries the ctwa_clid and the referral. The message arrives in the linked WhatsApp sandbox and the messages webhook goes to your WhatsApp application's callback, with referral.source_id equal to the ad id. To wait for it: npx mimicr wait whatsapp:meu-sandbox message direction=inbound wa_id=5511999990000.

8. Read the metrics

bash
curl --url 'https://meta-ads.mimicr.dev/v27.0/120200539998049712/insights?level=ad&fields=ad_id,spend,impressions,clicks,actions&date_preset=today' \
  --header 'Authorization: Bearer <token>'

The click adds one impression, one click and one started conversation (onsite_conversion.messaging_conversation_started_7d). To see the delivery generated by the budget, advance the clock: npx mimicr clock meta-ads +6h.

Next steps