The Marketing API allows you to build target Custom Audiences from customer information. This includes email addresses, phone numbers, names, dates of birth, gender, locations, App User IDs, Page Scoped User IDs, Apple's Advertising Identifier (IDFA), or Android Advertising ID.
Meta Business Account, sometimes referred to as Business Manager account or simply Business account, is being renamed to business portfolio. This change will appear gradually across Meta technologies. The change is cosmetic only and does not affect Meta Business Account IDs (business portfolio IDs).
As the owner of your business's data, you are responsible for creating and managing this data. This includes information from your Customer Relationship Management (CRM) systems. To create audiences, you must share your data in a hashed format to maintain privacy. See Hashing and Normalizing Data. Meta compares this with our hashed data to see if we should add someone on Facebook to your ad's audience.
You can add an unlimited number of records to an audience, but only up to 10000 at a time. Changes to your Custom Audiences don't happen immediately and usually take up to 24 hours. The number of records you request to remove and/or the number of Custom Audiences your account contains will increase the amount of time it takes to process this request.
To improve how advertisers create and manage their audiences, Customer File Custom Audiences that have not been used in any active ad sets in over two years will be flagged for deletion on a rolling basis. You will need to provide us with your instructions before we take any action. Once audiences are moved to the “Expiring Audience” stage and flagged, you will need to provide your instructions by either using the flagged audience in an active ad set, which we will consider an instruction to retain the audience, or by deciding not to use the flagged audience in an active ad set, which we will consider an instruction to delete the audience. For more information, see the Custom Audiences Overview documentation.
If you share conversion events using the Conversions API, you can create a website for a custom audience without additional data uploads. However, you can continue uploading supported customer information to create a Customer File Custom Audience.
Use our new Replace API to completely remove existing users of an audience and replace them with a new set of users. An audience update made with the Replace API does not move your ad set back to the learning phase.
Specify subtype=CUSTOM
and customer_file_source
in your API call.
curl -X POST \
-F 'name="My new Custom Audience"' \
-F 'subtype="CUSTOM"' \
-F 'description="People who purchased on my website"' \
-F 'customer_file_source="USER_PROVIDED_ONLY"' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/customaudiences
Name | Description |
---|---|
| Describes how the customer information in your Custom Audience was originally collected.
|
| Custom Audience name |
| Custom Audience description |
| Type of Custom Audience |
Use a POST
API call to the /{audience_id}/users
endpoint to specify the list of users you want to add to your Custom Audience.
Name | Description |
---|---|
| Required Example { "session_id":9778993, "batch_seq":10, "last_batch_flag":true, "estimated_num_total":99996 } |
| Required Example { "schema":"EMAIL_SHA256", "data": [ ["<HASHED_DATA>"], ["<HASHED_DATA>"], ["<HASHED_DATA>"] ] } |
If you want to enable Limited Data Use for people in California via customer list custom audiences on or after June 1, 2023, you must upload new audiences or update your existing audiences with the Limited Data Use flag. Regularly update and maintain your audiences and people’s Limited Data Use statuses as needed.
Please note that a Limited Data Use flag applied to a user in one audience will not automatically carry over to different audiences. In the same way advertisers must manage each of their existing customer list custom audiences separately by the criteria they select, the Limited Data Use flag must be applied separately to each audience they leverage for their advertising.
To explicitly NOT enable LDU
for the record, you can either send an empty data_processing_options
array or remove the field in the payload. Example of an empty array:
{ "payload": { "schema": [ "EMAIL", "DATA_PROCESSING_OPTIONS" ], "data": [ [ "<HASHED_DATA> ", [] ] ] } }
To explicitly enable LDU
, and have Meta perform geolocation (by not including state and country of the given record), specify an array containing LDU
for each record:
{ "payload": { "schema": [ "EMAIL", "DATA_PROCESSING_OPTIONS" ], "data": [ [ "<HASHED_DATA> ", ["LDU"] ] ] } }
To enable LDU and manually specify the location:
{ "customer_consent": true, "payload": { "schema": [ "EMAIL", "DATA_PROCESSING_OPTIONS", "DATA_PROCESSING_OPTIONS_COUNTRY", "DATA_PROCESSING_OPTIONS_STATE" ], "data": [ [ "<HASHED_DATA>", ["LDU"], 1, 1000 ] ] } }
session
FieldsName | Description |
---|---|
| Required |
| Required |
| Required Indicate to our systems that all batches for the ongoing Replace session have been provided. When set to |
| Optional |
A successful response includes a JSON object with the following fields:
Name | Description |
---|---|
| Audience identifier |
| Session ID you passed in |
| Total number of users received in this session so far |
| Number of entries sent with incorrect hashing. Those entries did not return a match and are not added to the custom audience. This is not an exact number, but it represents the number range of users that did not match. |
| Up to 100 samples of invalid entries found in the current request |
Learn more about sharing your Custom Audience with business objects.
Use a DELETE
API call to the /{audience_id}/users
endpoint to specify the list of users you want to remove from your Custom Audience.
curl -X DELETE \ --data-urlencode 'payload={ "schema": "EMAIL_SHA256", "data": [ "<HASHED_DATA>", "<HASHED_DATA>", "<HASHED_DATA>" ] }' \ -d 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
Or, you can add the method
parameter and set it to DELETE
in the POST
request used to add audience members.
You can remove people from a list with EXTERN_ID
, if available.
curl -X DELETE \ --data-urlencode 'payload={ "schema": "EXTERN_ID", "data": [ "<ID>", "<ID>", "<ID>" ] }' \ -d 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
You can remove a list of people from all custom audiences across your ad account using this endpoint.
There may be some reasons why this information is not processed. For example, if the ad account is not owned by a business portfolio, you have not yet accepted the Custom Audience Terms, or the information does not match with a user.
To remove an Accounts Center account, include the same fields as in user update and make a HTTP DELETE
call to:
https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/usersofanyaudience
To increase the match rate for your records, provide multiple keys in an array of individual keys; for example, [EXTERN_ID
, LN
, FN
, EMAIL
]. While you don't need to hash EXTERN_ID
, you must hash all personally identifying information, such as emails and names. For details, see Hashing and Normalizing Data.
You can provide some or all multi-keys for a record. For details, see multi-key extern id matching.
curl \ -F 'payload={ "schema": [ "FN", "LN", "EMAIL" ], "data": [ [ "<HASH>", "<HASH>", "<HASH>" ], [ "<HASH>", "<HASH>", "<HASH>" ] ] }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
PAGEUID
If you use the PAGEUID
key, you must also include a list of page IDs. You can only send us one PAGEUID
, which should be an array with one element.
curl -X POST \ -F 'payload={ "schema": [ "PAGEUID" ], "is_raw": "true", "page_ids": [ "<PAGE_IDs>" ], "data": [ [ "<HASH>", "<ID>", "<ID>", "<VALUE>" ], [ "<HASH>", "<ID>", "<ID>", "<VALUE>" ], [ "<HASH>", "<ID>", "<ID>", "<VALUE>" ] ] }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
You must hash data as SHA256
; we don't support other hashing mechanisms. This is required for all data except External Identifiers, App User IDs, Page Scoped User IDs and Mobile Advertiser IDs.
Before you hash your data, normalize it so we can handle it. Only First name (FN
) and Last Name (LN
) support special characters and non-Roman alphabets. For the best match results, provide the Roman alphabet translation with no special characters.
for examples of properly normalized and hashed data for the parameters below.
Key | Guidelines |
---|---|
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required |
| Hashing required Use lowercase, 2-letter country codes in ISO 3166-1 alpha-2. |
| Hashing NOT required Use all lowercase, and keep hyphens. |
Provide SHA256
values for normalized keys and HEX
representations of this value, using lowercase for A through F. The hash function in PHP converts normalized emails and phone numbers.
Example | Result |
---|---|
| f1904cf1a9d73a55fa5de0ac823c4403ded71afd4c3248d00bdcd0866552bb79 |
| 1ef970831d7963307784fa8688e8fce101a15685d62aa765fed23f3a2c576a4e |
You can match people for an audience with your own identifiers, known as External Identifiers (EXTERN_ID
). This can be any unique ID from the advertiser, such as loyalty membership IDs, user IDs, and external cookie IDs.
While you don't need to hash this ID, you must hash all Personally Identifying Information (PII) that you send with the EXTERN_ID
s.
For better matching, you should also use the exact format when you send the IDs. For example, if you choose to hash using SHA256, make sure to use the same hashed value.
You can use these IDs as individual keys to delete people from Custom Audiences or create new Custom Audiences. This way you don't need to re-upload any other matching keys. If you tag someone with hashed personal information and EXTERN_ID
, we give EXTERN_ID
lower precedence when we match them with people on Facebook.
The data retention period for EXTERN_ID
is 90 days.
You can reuse the EXTERN_ID
mapping to build customer file custom audiences within a single ad account.
If you have an audience of EXTERN_ID
fields in your ad account, create a new audience with just these identifiers.
curl \ -F 'payload={"schema":"EXTERN_ID","data":["<ID>","<ID>"]}' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
You can also add people tagged EXTERN_ID
and with multi-key matching.
curl \ -F 'payload={ "schema": [ "EXTERN_ID", "FN", "EMAIL", "LN" ], "data": [ [ "<ID>", "<HASH>", "<HASH>", "<HASH>" ], [ "<ID>", "<HASH>", "<HASH>", "<HASH>" ], [ "<ID>", "<HASH>", "<HASH>", "<HASH>" ] ] }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/<VERSION>/<CUSTOM_AUDIENCE_ID>/users
We support EXTERN_ID
parameters for individual ad accounts. We cannot use values from one ad account for any other ad accounts, even if the accounts belong to the same entity.
The /<CUSTOM_AUDIENCE_ID>/usersreplace
endpoint allows you to perform 2 actions with one API call:
Using the /<CUSTOM_AUDIENCE_ID>/usersreplace
endpoint allows you to automatically delete all existing users rather than having to upload a list of users you want to delete. This endpoint does not reset your ad set's learning phase when an audience is part of active ad sets unlike POST or DELETE API calls to the /<CUSTOM_AUDIENCE_ID>/users
endpoint.
The Replace Users API only works with audiences that meet the following requirements:
/<CUSTOM_AUDIENCE_ID>/users
endpoint to add and remove users.CUSTOM
.Before you start a replace process, we recommend the following:
operation_status
is Normal
. You cannot perform a replace operation if there is one already being executed.
Don't add or remove users via /<CUSTOM_AUDIENCE_ID>/users
during an ongoing replace operation via /<CUSTOM_AUDIENCE_ID>/usersreplace
. If you try performing a second replace operation before the first is completed, you will receive a message indicating a replace operation is already in progress.
The maximum duration window for 1 replace session is 90 minutes. The API will reject any batches for a session received after 90 minutes from the time the session started. If you need to send batches for a duration longer than 90 minutes, wait until the replace operation for that session is done, then use the /<CUSTOM_AUDIENCE>/users
endpoint’s add operation for the rest of your uploads.
Once your audience is ready, specify the list of users you want to replace with your custom audience using a POST
call to /<CUSTOM_AUDIENCE_ID>/usersreplace
.
operation_status
switches to replace_in_progress
. operation_status
switches to replace_error
.You can include the following parameters in your POST
call to /<CUSTOM_AUDIENCE_ID>/usersreplace
:
Name | Description |
---|---|
Type: JSON object | Required. Used to track if a specific batch of users has been uploaded. Must include a session ID and batch information. See Session Fields. You can add up to 10,000 people to an audience at a given time. If you have more than 10,000 people, split your session into multiple batches, which should all have 1 session ID. Example: { 'session_id':9778993, 'batch_seq':10, 'last_batch_flag':true, 'estimated_num_total':99996 } |
Type: JSON object | Required. Used to provide the information you want to be uploaded to your audience. Must include schema and data —see Payload Fields for more information. Example: { "schema":"EMAIL", "data":["<HASHED_EMAIL>", "<HASHED_EMAIL>", "<HASHED_EMAIL>" ] } |
Name | Description |
---|---|
Type: 64-bit integer | Required. Used to track the session. You must generate this identifier and the number must be unique within the same ad account. |
Type: integer | Required. Must start at |
Type: boolean | Optional. Indicates all batches for the ongoing Replace session have been provided. When set to true, no further batches are accepted for that session. If you do not set this flag, the session is automatically terminated 90 minutes after the first batch is received. Any batch received after 90 minutes is also discarded. |
Type: integer | Optional. Estimated total number of users to be uploaded in this session. Used by our system to improve a session's processing. |
Name | Description |
---|---|
Type: string or | Required. Specify what type of information you will provide. It can be a single key or multi-key from this list:
|
Type: JSON_Array | Required. List of data corresponding to the schema. Examples:
|
Once you make your POST
request, you get a response with the following fields:
Name | Description |
---|---|
Type: integer | Account identifier. |
Type: integer | Session ID you have previously provided. |
Type: integer | Total number of users received in this session so far. |
Type: integer | Total number of users with invalid format or unable to be decoded. If this number is not zero, re-check your data. |
| Up to 100 samples of invalid entries in current request. Re-check your data. |
All errors returned from the Replace endpoint have error code 2650. Here are some of the most common error subcodes returned, as well as guidance on how to resolve them.
Error SubCode | Description | What To Do |
---|---|---|
1870145 | Audience Update In Progess | You can't replace a customer list custom audience that is in the process of being updated. Wait for the audience availability to become "Normal" and try again. |
1870158 | Replace Session Timed Out | You've reached the 90-minute time limit for your replace batch session. Your customer list custom audience will be replaced with what you've uploaded so far. To add more to the custom audience, wait until the replace process is finished, and then use the |
1870147 | Invalid Upload Batch for Replace | The first |
1870159 | Replace Session Finished | This replace operation is already finished because you uploaded a batch with |
1870148 | Something Went Wrong | Your customer list was not fully updated. If your audience size is significantly differ than expected, consider trying again. |
1870144 | DFCA Size Not Supported For Replace | You can't replace a customer list customer audience that has a size of 100 million or more. |
There are other types of audiences you can build and target, or share:
Custom Audiences From Your Website — Create an audience based on people who visited a specific page or made action on your website. Build an audience based on data from Meta Pixel on your site.
Custom Audiences From Your Mobile App — Create an audience based on people who use your mobile app. Build an audience based on data from App Events.
Lookalike Audiences — Identify people you already know and advertise to similar people on the Facebook app.
Offline Custom Audiences — Create an audience based on people who visited your store, made calls to your customer service, or took action through other offline means.
Canvas Engagement Audiences — Create an audience that contains anyone who engaged with your Canvas.