curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users \
-d '{"accountId": "1234567890", "schema": ["EMAIL", "PHONE"], "data": [["5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7", "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"]]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY', 'Content-Type': 'application/json'}
payload = {
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data[0][0] (EMAIL) is not a hash: expected 64 lowercase hex characters."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data has 12000 rows; the limit is 10000 per request."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "id 23851234567890123 is not a custom audience of ad account 123456789."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}
Facebook Ads
Audience Members
Add people to, or remove them from, a Facebook customer-list audience by sending SHA-256 hashes of their email, phone or other identifiers.
POST
/
ads
/
facebook
/
audiences
/
{id}
/
users
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users \
-d '{"accountId": "1234567890", "schema": ["EMAIL", "PHONE"], "data": [["5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7", "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"]]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY', 'Content-Type': 'application/json'}
payload = {
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data[0][0] (EMAIL) is not a hash: expected 64 lowercase hex characters."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data has 12000 rows; the limit is 10000 per request."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "id 23851234567890123 is not a custom audience of ad account 123456789."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}
Add people to a customer-list audience created with Create Audience (
type: customerList), or remove them. You send each person as SHA-256 hashes of their normalized identifiers; Meta matches the hashes to accounts; the raw values never leave your system.
DELETE /ads/facebook/audiences/{id}/users takes the same body and removes the people instead.
- A list is usable in a boost once Meta has matched at least 100 people, which can take up to 48 hours. Audiences shows
status.readywhen it is. - Each request carries at most 10,000 rows and a body of at most 10 MiB. Send a larger list as several requests.
- Through GraphQL,
addAdAudienceUsersandremoveAdAudienceUserscarry a smaller batch: about 900 rows with oneschemacolumn, fewer with more columns. A larger GraphQL request getsRequest body too large.Send full 10,000-row batches to these REST endpoints. - If one request of a larger upload fails, the requests before it stay in the audience. Send the failed one again: Meta de-duplicates rows.
- The id must be a custom audience on the ad account named by
accountId. Any other id returns a400withcode: 101.
Hashed identifiers are personal data
A hashed email or phone number is still personal data under GDPR and similar laws. When you upload a list:- You are the data controller. You need a lawful basis, usually the consent of the people on the list, to use their data for advertising, as your privacy policy and Meta’s Custom Audience terms require.
- Ayrshare is a processor. We pass the hashes to Meta and keep nothing but the counts: no row of the body is logged, cached or stored, and the response never echoes a row.
- You hash before sending. Ayrshare never hashes for you. A value that is not a hash is refused before anything is sent to Meta.
How to hash
Normalize each value the way Meta’s customer list rules describe, then hash it with SHA-256 and send the result as 64 lowercase hex characters. In short:EMAIL: trim spaces and lowercase, for examplejane@example.com.PHONE: digits only, with the country code and no leading zeros or+, for example14155551234.FN,LN,CT,ST,COUNTRY: lowercase, no punctuation or spaces;COUNTRYas a two-letter code;STas a two-letter code for a US state, otherwise the region’s name.ZIP: lowercase, no spaces; the first five digits for US codes.GEN:morf.DOBY: four-digit year.DOBMandDOBD: two digits.FI: the first initial, lowercase.
Header Parameters
Path Parameters
The customer-list audience id, from Create Audience or Audiences.
Body Parameters
The identifier in each column, in order. Supported:
EMAIL, PHONE, GEN, DOBY, DOBM, DOBD, FN, LN, FI, CT, ST, ZIP, COUNTRY. Meta takes MADID, EXTERN_ID and PAGEUID unhashed, so they are not accepted here.One row per person: an array with one SHA-256 hash per
schema column, as 64 lowercase hex characters. At most 10,000 rows.A cell that is not such a hash, a row of the wrong width, or an unsupported key returns a 400 with code: 101 before anything is sent to Meta. The message names the row and column, never the value, for example data[1][0] (EMAIL) is not a hash: expected 64 lowercase hex characters.Response
Counts only:received: rows Meta took.invalid: rows Meta could not read.batches: how many uploads the rows were sent in.
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users \
-d '{"accountId": "1234567890", "schema": ["EMAIL", "PHONE"], "data": [["5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7", "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"]]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY', 'Content-Type': 'application/json'}
payload = {
"accountId": "1234567890",
"schema": [
"EMAIL",
"PHONE"
],
"data": [
[
"5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
"a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
]
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data[0][0] (EMAIL) is not a hash: expected 64 lowercase hex characters."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "data has 12000 rows; the limit is 10000 per request."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "id 23851234567890123 is not a custom audience of ad account 123456789."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}