curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences \
-d '{"accountId": "1234567890", "name": "Site visitors 30d", "type": "website", "pixelId": "987654321098765", "retentionDays": 30, "urlContains": ["/pricing"]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
})
})
.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",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"audience": {
"id": "23851234567890123",
"name": "Site visitors 30d",
"type": "website",
"size": null,
"status": { "ready": false, "code": 300, "description": "This audience is still being populated." },
"created": "2026-10-29T10:05:00.000Z"
}
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "ratio is not a recognised field."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "Creating a custom audience needs the Custom Audience terms accepted on ad account act_123456789. A person with a role on the account accepts them at https://business.facebook.com/ads/manage/customaudiences/tos/?act=123456789"
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to create the audience. Please try again.",
"details": "Meta's reason"
}
Facebook Ads
建立受眾
建立由網站訪客、互動用戶、類似受眾或顧客名單組成的 Facebook 自訂受眾,用於推廣時納入或排除。
POST
/
ads
/
facebook
/
audiences
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences \
-d '{"accountId": "1234567890", "name": "Site visitors 30d", "type": "website", "pixelId": "987654321098765", "retentionDays": 30, "urlContains": ["/pricing"]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
})
})
.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",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"audience": {
"id": "23851234567890123",
"name": "Site visitors 30d",
"type": "website",
"size": null,
"status": { "ready": false, "code": 300, "description": "This audience is still being populated." },
"created": "2026-10-29T10:05:00.000Z"
}
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "ratio is not a recognised field."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "Creating a custom audience needs the Custom Audience terms accepted on ad account act_123456789. A person with a role on the account accepts them at https://business.facebook.com/ads/manage/customaudiences/tos/?act=123456789"
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to create the audience. Please try again.",
"details": "Meta's reason"
}
在 Facebook 廣告帳戶上建立自訂受眾。支援四種類型,透過
類似受眾沒有自己的國家:人員來自推廣的
顧客名單建立時為空。使用受眾成員新增人員。雜湊識別碼仍然是個人資料:上傳名單前請閱讀該頁面。
type 選擇:
website:Meta 像素在你的網站上偵測到的人。engagement:與 Facebook 粉絲專頁、Instagram 帳戶或影片互動過的人。lookalike:與你已有受眾相似的人。customerList:你自己的人員名單,透過受眾成員以雜湊識別碼填充。
audience 下傳回,status.ready: false。Meta 會在接下來幾個小時內填充它;列出受眾以查看 status.ready 何時變為 true,然後在推廣貼文時將其 id 用於 targeting.audiences 或 targeting.excludedAudiences。
在建立或使用任何受眾之前,廣告帳戶中擁有角色的人員必須在
https://business.facebook.com/ads/manage/customaudiences/tos/?act=<ad account id> 接受一次 Meta 的 Custom Audience 條款。Ayrshare 無法代你接受。在此之前,此端點會傳回帶有 code: 101 的 400,details 會指出帳戶以及接受條款的頁面。廣告帳戶會在 tosAccepted.customAudienceTos 中顯示是否已接受。Meta 不允許在住房、就業或金融廣告中使用類似受眾。屬於這些特殊廣告類別之一的推廣可以納入或排除網站、互動和顧客名單受眾,但不能使用類似受眾。
請求頭參數
請求體參數
每種type 都接受以下參數:
要在其上建立受眾的廣告帳戶,來自廣告帳戶,帶或不帶
act_ 前綴皆可。website、engagement、lookalike 或 customerList。每種類型只接受下方列出的自身欄位。來自其他類型的欄位會傳回帶有 code: 101 的 400 並指出該欄位。為每個新受眾提供一個新的唯一值,例如 UUID。如果你以相同的金鑰重複請求,Ayrshare 會傳回第一次的回應,並標記
idempotentReplayed: true,不會建立第二個受眾。你也可以改為在 Idempotency-Key 標頭中傳送該金鑰;如果兩者都傳送,它們必須一致。將金鑰用於不同的請求,或在第一個請求仍在處理時重複使用該金鑰,會傳回 409。503 表示無法保留該金鑰且未建立任何內容:請稍後以相同的金鑰重試。網站受眾
互動受眾
計算的互動類型。這些值是 Meta 自己的名稱,取決於
source:page:page_engaged,page_visited,page_liked,page_messaged,page_cta_clicked,page_or_post_save,page_post_interactioninstagram:ig_business_profile_all,ig_business_profile_engaged,ig_business_profile_visit,ig_business_profile_ad_saved,ig_user_messaged_business,ig_ad_like,ig_ad_comment,ig_ad_share,ig_ad_save,ig_ad_cta_click,ig_ad_carousel_swipe,ig_organic_like,ig_organic_comment,ig_organic_share,ig_organic_save,ig_organic_swipe,ig_organic_carousel_swipevideo:video_watched,video_completed,video_view_10s,video_view_15s,video_view_25_percent,video_view_50_percent,video_view_75_percent
code: 101 的 400,並列出該來源可用的值。類似受眾
用於尋找相似人員的受眾,來自受眾。Meta 需要其中至少有 100 人。
targeting.locations 指定的國家。傳送 country 會傳回帶有 code: 101 的 400。Meta 需要幾個小時來填充類似受眾。
顧客名單受眾
名單資料的來源,使用 Meta 的用語:
USER_PROVIDED_ONLY(由本人提供給你)、PARTNER_PROVIDED_ONLY(由合作夥伴提供給你)或 BOTH_USER_AND_PARTNER_PROVIDED。curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences \
-d '{"accountId": "1234567890", "name": "Site visitors 30d", "type": "website", "pixelId": "987654321098765", "retentionDays": 30, "urlContains": ["/pricing"]}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/audiences", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"accountId": "1234567890",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
})
})
.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",
"name": "Site visitors 30d",
"type": "website",
"pixelId": "987654321098765",
"retentionDays": 30,
"urlContains": [
"/pricing"
]
}
r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences', json=payload, headers=headers)
print(r.json())
{
"status": "success",
"audience": {
"id": "23851234567890123",
"name": "Site visitors 30d",
"type": "website",
"size": null,
"status": { "ready": false, "code": 300, "description": "This audience is still being populated." },
"created": "2026-10-29T10:05:00.000Z"
}
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "ratio is not a recognised field."
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "Creating a custom audience needs the Custom Audience terms accepted on ad account act_123456789. A person with a role on the account accepts them at https://business.facebook.com/ads/manage/customaudiences/tos/?act=123456789"
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to create the audience. Please try again.",
"details": "Meta's reason"
}