Skip to main content
Socialift
Capability

Meta Marketing API: ads and targeting

Socialift brings the Meta Marketing API into the Python SDK: ad accounts, interest and location targeting, reach estimates without spending, the campaign → ad set → ad chain, one-call boosting of an Instagram post, insights with breakdowns, and custom and lookalike audiences. In the dashboard these calls run on the connected user's personal Facebook token; in the SDK you pass any token that has the ads permissions.

Updated:

What is the Meta Marketing API for?

The Meta Marketing API is the official interface for managing Facebook and Instagram advertising from software instead of the Ads Manager UI. With it you create campaigns, ad sets and ads, configure targeting, change budgets and pull results broken down by age, gender, region or placement.

What makes the Marketing API hard is its nested objects and Meta-specific rules: targeting is a sprawling JSON structure, budgets are passed in the currency's smallest unit, and Meta removes interests once they are outdated. Socialift builds targeting from simple fields, accepts budgets in normal units and converts them, and lets you check whether saved interests are still valid.

ads_management to manage campaigns, ads_read for reporting only. Standard Access is enough for your own ad accounts; managing clients' accounts needs Advanced Access — App Review plus Business Verification. The Marketing API itself also starts on a heavily rate-limited tier.

What ships out of the box

01

Ad accounts

The ad accounts the user can access, with their currency and Meta's minimum daily budget.

02

Targeting research

Search interests, locations, locales, behaviour and demographic categories; get similar-interest suggestions and validate saved interests.

03

Reach estimates

Find out how many people a targeting spec covers — without creating an ad or spending money.

04

Campaign management

Campaigns, ad sets, ads, creatives, image upload and ad previews; ACTIVE/PAUSED status, daily budget updates and deletion.

05

Post boosting

Campaign, ad set, creative and ad for an existing Instagram post in a single call — all created PAUSED. Posts containing copyrighted music or interactive elements such as filters cannot be boosted.

06

Insights with breakdowns

Insight rows broken down by age, gender, country, region, placement and device.

Targeting: from search to reach estimate

Research the audience first, then assemble the targeting and see how many people it covers before anything is created.

targeting.py
import asyncio, os
from socialift import Ads

async def main():
    async with Ads(app_secret=os.environ["FACEBOOK_APP_SECRET"], graph_version="v25.0") as ads:
        token = os.environ["META_USER_TOKEN"]
        interests = await ads.search_interests(token, "fitness")
        targeting = ads.build_targeting(countries=["UZ"], age_min=18, age_max=45,
                                        interests=[{"id": interests[0]["id"]}],
                                        advantage_audience=False)  # exact age range
        print(await ads.delivery_estimate(token, ad_account_id="act_123", targeting=targeting))

asyncio.run(main())

build_targeting turns simple fields into the deep targeting object Meta expects. delivery_estimate is called before any ad exists and shows the audience size without spending — Meta returns an approximate range, not an exact number. With Advantage+ audience on (the default, advantage_audience=True), Meta fixes age_max at 65 and accepts age_min only between 18 and 25.

Ads does not read the Graph API version from environment variables, so the sample passes graph_version="v25.0" explicitly. Marketing API versions expire — check the current one in Meta's changelog.

Boosting an Instagram post in one call

boost_post turns an existing post into an ad by creating the campaign, ad set, creative and ad in sequence. Everything stays PAUSED — you review it and switch it on yourself.

boost.py
import asyncio, os
from socialift import Ads

async def main():
    async with Ads(app_secret=os.environ["FACEBOOK_APP_SECRET"], graph_version="v25.0") as ads:
        token = os.environ["META_USER_TOKEN"]
        result = await ads.boost_post(
            token,
            ad_account_id="act_123",
            ig_user_id="1784...",
            media_id="1790...",
            name="Reels boost",
            daily_budget_major=10.0,  # ad account currency, e.g. USD 10
            goal="traffic",
            link="https://example.uz/offer",
            targeting=ads.build_targeting(countries=["UZ"], age_min=18, platforms=["instagram"]),
        )
        # Results broken down by age and gender
        rows = await ads.insights_rows(
            token, "act_123", level="campaign",
            date_preset="last_7d", breakdowns=["age", "gender"],
        )

asyncio.run(main())

daily_budget_major is in the ad account currency's main unit; the SDK multiplies it by 100 before sending it to Meta. That is correct for offset-100 currencies (USD, EUR, RUB, …); for offset-1 currencies (JPY, KRW, IDR, VND, …) check the result against the minimum budget from ad_accounts. UZS is not in Meta's list of ad account currencies.

The sample passes targeting explicitly and without age_max: in an ad set with Advantage+ audience on, Meta does not let you set age_max.

A Marketing API endpoint without a dedicated SDK method can still be called: await ads.call(token, "act_123/adcreatives", method="GET", fields="id,name").

Audiences and pixels

Beyond targeting, audiences let you point ads at a specific group of people.

Custom audience
An audience built from your customer list. add_audience_users normalises emails and phone numbers to Meta's rules and SHA-256-hashes them on your own server where the SDK runs — no plain text reaches Meta. The ad account must have accepted the Custom Audience Terms.
Lookalike audience
People in the chosen country most similar to a source audience. ratio=0.01 is the closest 1% of that country's population; allowed range 0.01–0.20. The source audience needs at least 100 members.
Pixels
The pixels attached to an ad account can be listed through the API.
Lead Ads context
Each lead coming from Lead Ads can carry the targeting context of its campaign and ad set — so you can see which audience produced it.

Launching the ads workflow

  1. Request permissions

    Add ads_management and ads_read to your Meta app. Standard Access covers your own ad accounts; for client accounts get Advanced Access through App Review and Business Verification.

  2. Connect a Facebook account

    Sign in with Facebook on the Connections (Ulanishlar) page of the dashboard: ads calls run on that personal user token.

  3. Research the audience

    Search interests and locations, assemble the targeting and estimate reach without spending.

  4. Create the campaign

    Create a campaign, ad set and ad, or boost an existing Instagram post with boost_post — all PAUSED.

  5. Review, activate and monitor

    Switch the status to ACTIVE, watch results by breakdown and adjust the daily budget.

What to watch when automating ads

  • Everything is created PAUSED — nothing is shown until you set it to ACTIVE.
  • Pass budgets in the ad account currency's main unit and check them against the minimum daily budget from ad_accounts.
  • Re-validate saved interests from time to time — Meta removes outdated ones.
  • When you upload a customer list, emails and phone numbers are SHA-256-hashed on the server running the SDK and only the hashes go to Meta.
  • Add ads_management and ads_read to your Meta app. Standard Access covers your own ad accounts; for client accounts get Advanced Access through App Review and Business Verification.
  • Playground requests are real: actions that affect budgets ask for explicit confirmation there.

Frequently asked questions

Can I boost an Instagram post through the API?

Yes. boost_post creates the campaign, ad set, creative and ad in a single call. All of them stay PAUSED, so the ad does not run until you have reviewed and activated it. Posts containing copyrighted music or interactive elements such as filters cannot be boosted.

Can I find out the audience size without creating an ad?

Yes. delivery_estimate returns a reach estimate for the chosen targeting without spending anything. Call it before you create the campaign.

Which permissions does the Marketing API need?

ads_management to manage campaigns, ads_read for reporting only. Standard Access is enough for your own ad accounts; managing clients' accounts needs Advanced Access — App Review plus Business Verification. The Marketing API itself also starts on a heavily rate-limited tier.

How are customer emails and phone numbers sent?

add_audience_users normalises emails and phone numbers the way Meta requires (lowercase email, digits-only phone with country code) and SHA-256-hashes them on your server where the SDK runs. No plain-text list is sent to Meta.

Is Socialift an ad agency or a Meta partner?

Neither. Socialift is an integration layer for developers. Ads are managed in your own ad account with your own token, and Socialift is not an official Meta partner.

Do the SDK's ads methods work during the free month?

Yes. For the first 30 days the token unlocks every SDK feature, including the Ads client and the Lead Ads methods. After that the token renews in 30-day periods from your balance and its features depend on the token's plan — “Tekshirish va muhitlar” (Check and environments) in the dashboard shows the exact list. The dashboard Playground works regardless of plan.

Sources

  1. Meta — Advantage+ audience
  2. Meta — Ad account currencies
  3. Meta — Custom Audiences
  4. Meta — Lookalike Audiences
  5. Meta — Using Instagram posts as ads
  6. Meta — Marketing API versioning

Related pages

Manage ads from code

Get a token, connect your Facebook account and pull your first reach estimate today.

Get a free token →