get_ads_by_campaign
Retrieve ads from a specific Facebook campaign with filtering, pagination, and field selection. Get details like status, creative, and targeting for analysis.
Instructions
Retrieves ads associated with a specific Facebook campaign.
This function allows querying all ads belonging to a specific campaign, with filtering options, pagination, and field selection.
Args: campaign_id (str): The ID of the campaign to retrieve ads from. fields (Optional[List[str]]): A list of specific fields to retrieve for each ad. If None, a default set of fields will be returned. Common fields include: - 'id': The ad's ID - 'name': The ad's name - 'adset_id': The ID of the ad set this ad belongs to - 'creative': The ad creative details - 'status': The current status of the ad - 'effective_status': The effective status including review status - 'bid_amount': The bid amount for this ad - 'created_time': When the ad was created - 'updated_time': When the ad was last updated - 'targeting': Targeting criteria - 'preview_shareable_link': Link for previewing the ad filtering (Optional[List[dict]]): A list of filter objects to apply to the data. Each object should have 'field', 'operator', and 'value' keys. limit (Optional[int]): Maximum number of ads to return per page. Default is 25. after (Optional[str]): Pagination cursor for the next page. From response['paging']['cursors']['after']. before (Optional[str]): Pagination cursor for the previous page. From response['paging']['cursors']['before']. effective_status (Optional[List[str]]): Filter ads by their effective status. Options include: 'ACTIVE', 'PAUSED', 'DELETED', 'PENDING_REVIEW', 'DISAPPROVED', 'PREAPPROVED', 'PENDING_BILLING_INFO', 'ADSET_PAUSED', 'ARCHIVED', 'IN_PROCESS', 'WITH_ISSUES'.
Returns: Dict: A dictionary containing the requested ads. The main results are in the 'data' list, and pagination info is in the 'paging' object.
Example: ```python # Get all active ads from a campaign ads = get_ads_by_campaign( campaign_id="23843211234567", fields=["name", "adset_id", "effective_status", "created_time"], effective_status=["ACTIVE"], limit=50 )
# Fetch the next page if available using the pagination cursor
next_page_cursor = ads.get("paging", {}).get("cursors", {}).get("after")
if next_page_cursor:
next_page = get_ads_by_campaign(
campaign_id="23843211234567",
fields=["name", "adset_id", "effective_status", "created_time"],
effective_status=["ACTIVE"],
limit=50,
after=next_page_cursor
)
```
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| after | No | ||
| limit | No | ||
| before | No | ||
| fields | No | ||
| filtering | No | ||
| campaign_id | Yes | ||
| effective_status | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |