You are on page 1of 12

How to Publish Ads in

Facebook(Meta) through API


Sayantan Sarkar · Follow
5 min read · Jun 9, 2023

Photo by Alexander Shatov on Unsplash

The Facebook Marketing API is a powerful tool that can help businesses of
all sizes reach their target audiences more effectively. By integrating the API
into your app, you can Create and Manage Ads, Target your ads, Track your
results. the Facebook Marketing API is a valuable tool that can help
businesses to grow their reach and increase their ROI. If you are looking for
a way to improve your marketing efforts, I encourage you to explore the API
from — Meta Marketing API (facebook.com). It is a powerful tool that can
help you to reach your target audiences more effectively, track the results of
your campaigns, and optimize your campaigns for better results.

Before starting with Meta Marketing API, I would highly recommend you go
through this article to publish any post to Facebook (Meta) Page-

How to post content on Facebook (Meta) from your server app


Facebook recently launched the Facebook Meta platform, which
enables developers to build immersive and interactive…
medium.com

So, now you have an business app created in your developer account with
Facebook (Meta). Now go to left section of your App Dashboard page. Click
Add Products and choose Marketing Api and click on Set up.

After this, Marketing API would appear on the left section under Products.
Click on that to expand and show the options. From that, click on tools. Now
you would see something like this -
App Dashboard

From ‘Get Access Token’ section, click on ‘Get Token’ to get access token and
keep note of it in somewhere safely. We will use this token while calling
marketing api.

Now the setup to call Marketing API is complete. But before jumping into
showing the calling steps, I will tell you about Facebook (Meta) Ad Campaign
structure.

Ad Campaign Structure sourced from Meta

Campaign
These objects contain your advertising objective and one or more ad sets. This helps
you optimize and measure results for each advertising objective.
Ad Sets
Ad sets have one or more ads. You define budget and schedule for each ad set.
Create an ad set for each target audience with your bid; ads in the set target the
same audience with the same bid. This helps control the amount you spend on each
audience, determine when the audience will see your ads, and provides metrics for
each audience.

Ads
Contains ad creative. Create multiple ads in each ad set to optimize ad delivery
based different images, links, video, text, or placements.

Ad creatives
Contain just the visual elements of the ad and you can’t change them once they’re
created. Each ad account has a creative library to store creatives for reuse in ads.

So, first we have to create a campaign. Within that, we have to create an ad


set. After that, we have to upload a image/video to that Ad account and
retrieve a hash. Once you receive a hash, you have to create an Ad Creative
using some page related info where you want to run your advertisement. At
the last step, you have to create ad using creative_id and adset_id.

Note: A lot of customization is possible by calling these same api with different
purpose and expecting different outcome. But to keep it simple, I have avoided
Open those
in app steps and tried to keep it minimalistic. Sign up Sign in

Search Write
Note: It is mandatory to add a payment method to complete the last step i.e. create
ad.

Step 1: Create a Campaign


Create a campaign with a business objective i.e. Sales, Leads, Traffic,
Engagement etc. After successful Post API call, you would receive a
campaign_id.
Create campaign

Step 2: Create Ad Set


After receiving campaign_id, you have to create Ad Set where you have to put
your optimization goal, bid amount, budget and target audience etc.

Read here to know more about different parameters you can pass to create
your ad set — https://developers.facebook.com/docs/marketing-
api/reference/ad-campaign/

After successful Post API call, you would receive an adset_id .


Create Ad Set

Step 3: Upload Image


This is the easiest step. You can upload an image from your machine or
server app and would receive a image_hash which would be used in next step
i.e. creating Ad Creative.

Step 4: Create Ad Creative


The purpose of this Ad Creative is design the actual ad which would be
displayed in Facebook Page feed. So, the main object we have to send here is
— object_story_spec where facebook page_id, image_hash (from earlier step),
action button type and url of where you want users to route after clicking
etc. can be set.

Ex- Sample data of object_story_spec -

{
"page_id":"114132124974698",
"link_data":{
"image_hash":"9935dd57c2ce958f98c5d17035603b2f",
"link":"https://facebook.com/114132124974698",
"message":"Try it out"
}
}

After successful Post API call, you would receive ad_creative_id.

Step 5: Create Ad
At last, you simply have to the following endpoint with adset_id and
creative_id received from earlier steps and Bam! your ad is created.
Create Ad

To check, you can navigate to Ad Manager of Facebook and under the section
of campaigns, you would find the campaign, ad set and ad which you have
just created by calling API.

While creating Facebook ads through calling marketing API, you can face
different kind of error messages. Most of them occurs due to mismatch of
objective in campaign and ad set or sometimes it happens that you are not
sending one parameter with the API call which is expected.

So, feel free to reach out to me in case you require any kind of consultation
according to your needs.

To get more Technology related content-

Follow me on Medium.

Connect with me on Twitter.


Facebook Facebook Marketing Advertising Facebook Graph Api Marketing

Written by Sayantan Sarkar Follow

24 Followers

Software Engineer 2 at Lexmark (India), Passionate about Technology, Startup and Love to
travel

More from Sayantan Sarkar

Sayantan Sarkar in Coinmonks Sayantan Sarkar

Is Blockchain really Dead ? Easy way to detect click event


Blockchain technology has been around for outside of div in Angular
over a decade, but it has only recently gaine… I was working on an application where the
requirement was something like this — when …

4 min read · May 27, 2023 2 min read · May 19, 2023

8 23 1
Sayantan Sarkar Sayantan Sarkar

Dynamic API Routes in NextJS Simple Steps to Send WhatsApp


Dynamic API routes are a powerful tool that Messages using API
can be used to improve the functionality and… Helpful Tips for small businesses to connect
with their customers

2 min read · Jun 17, 2023 4 min read · Sep 9, 2023

9 1 4 1

See all from Sayantan Sarkar

Recommended from Medium

Artturi Jalli Lukasz Zelezny SEO Consultant - https://seo.lond…

I Built an App in 6 Hours that Makes URL Rating


$1,500/Mo Have you ever wondered why some web
Copy my strategy! pages seem to be more popular or visible on…
· 3 min read · Jan 23, 2024 7 min read · Oct 18, 2023

7K 93

Lists

Modern Marketing Branding


63 stories · 423 saves 34 stories · 148 saves

What is ChatGPT? Growth Marketing


9 stories · 293 saves 10 stories · 49 saves

James Presbitero Jr. in Practice in Public Stefan Neefischer

These Words Make it Obvious That Machine Learning and Artificial


Your Text is Written By AI Intelligence in Google Ads
These 7 words are painfully obvious. They With the rise of machine learning (ML) and
make me cringe. They will make your reader… artificial intelligence (AI), it’s no longer a…

5 min read · Dec 31, 2023 4 min read · Aug 30, 2023

37K 972 6

Rajdatt kokate Travis Scott


Automate Instagram Posts with Revolutionizing Ad Creative
Python: A Step-by-Step Guide Testing with AI-Powered Solution…
📸 Do you want to streamline your Instagram Success hinges on the ability to capture and
posting process using Python? In this blog,… retain the attention of target audiences. With…

2 min read · Sep 8, 2023 · 6 min read · 5 days ago

3 187

See more recommendations

You might also like