meta-ads-mcp 0.10.0__tar.gz → 0.10.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/PKG-INFO +14 -2
  2. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/README.md +12 -0
  3. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/__init__.py +1 -1
  4. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/adsets.py +4 -3
  5. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/targeting.py +65 -21
  6. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/pyproject.toml +2 -2
  7. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_estimate_audience_size.py +15 -25
  8. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_estimate_audience_size_e2e.py +1 -1
  9. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_mobile_app_adset_creation.py +51 -0
  10. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/.github/workflows/publish.yml +0 -0
  11. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/.github/workflows/test.yml +0 -0
  12. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/.gitignore +0 -0
  13. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/CUSTOM_META_APP.md +0 -0
  14. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/Dockerfile +0 -0
  15. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/LICENSE +0 -0
  16. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/LOCAL_INSTALLATION.md +0 -0
  17. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/META_API_NOTES.md +0 -0
  18. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/RELEASE.md +0 -0
  19. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/STREAMABLE_HTTP_SETUP.md +0 -0
  20. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/examples/README.md +0 -0
  21. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/examples/example_http_client.py +0 -0
  22. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/future_improvements.md +0 -0
  23. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/images/meta-ads-example.png +0 -0
  24. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_auth.sh +0 -0
  25. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/__main__.py +0 -0
  26. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/__init__.py +0 -0
  27. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/accounts.py +0 -0
  28. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/ads.py +0 -0
  29. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/ads_library.py +0 -0
  30. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/api.py +0 -0
  31. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/auth.py +0 -0
  32. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/authentication.py +0 -0
  33. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/budget_schedules.py +0 -0
  34. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/callback_server.py +0 -0
  35. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/campaigns.py +0 -0
  36. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/duplication.py +0 -0
  37. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/http_auth_integration.py +0 -0
  38. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/insights.py +0 -0
  39. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/openai_deep_research.py +0 -0
  40. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/pipeboard_auth.py +0 -0
  41. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/reports.py +0 -0
  42. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/resources.py +0 -0
  43. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/server.py +0 -0
  44. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/meta_ads_mcp/core/utils.py +0 -0
  45. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/requirements.txt +0 -0
  46. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/setup.py +0 -0
  47. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/smithery.yaml +0 -0
  48. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/README.md +0 -0
  49. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/README_REGRESSION_TESTS.md +0 -0
  50. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/__init__.py +0 -0
  51. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/conftest.py +0 -0
  52. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/e2e_account_info_search_issue.py +0 -0
  53. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_account_info_access_fix.py +0 -0
  54. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_account_search.py +0 -0
  55. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_budget_update.py +0 -0
  56. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_budget_update_e2e.py +0 -0
  57. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_dsa_beneficiary.py +0 -0
  58. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_dsa_integration.py +0 -0
  59. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_duplication.py +0 -0
  60. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_duplication_regression.py +0 -0
  61. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_dynamic_creatives.py +0 -0
  62. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_get_account_pages.py +0 -0
  63. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_get_ad_creatives_fix.py +0 -0
  64. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_get_ad_image_quality_improvements.py +0 -0
  65. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_get_ad_image_regression.py +0 -0
  66. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_http_transport.py +0 -0
  67. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_insights_actions_and_values.py +0 -0
  68. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_integration_openai_mcp.py +0 -0
  69. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_mobile_app_adset_issue.py +0 -0
  70. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_openai.py +0 -0
  71. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_openai_mcp_deep_research.py +0 -0
  72. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_page_discovery.py +0 -0
  73. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_page_discovery_integration.py +0 -0
  74. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_targeting.py +0 -0
  75. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_targeting_search_e2e.py +0 -0
  76. {meta_ads_mcp-0.10.0 → meta_ads_mcp-0.10.2}/tests/test_update_ad_creative_id.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meta-ads-mcp
3
- Version: 0.10.0
4
- Summary: Model Context Protocol (MCP) plugin for interacting with Meta Ads API
3
+ Version: 0.10.2
4
+ Summary: Model Context Protocol (MCP) server for interacting with Meta Ads API
5
5
  Project-URL: Homepage, https://github.com/pipeboard-co/meta-ads-mcp
6
6
  Project-URL: Bug Tracker, https://github.com/pipeboard-co/meta-ads-mcp/issues
7
7
  Author-email: Yves Junqueira <yves.junqueira@gmail.com>
@@ -43,6 +43,7 @@ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for in
43
43
  - [Features](#features)
44
44
  - [Configuration](#configuration)
45
45
  - [Available MCP Tools](#available-mcp-tools)
46
+ - [Licensing](#licensing)
46
47
  - [Privacy and Security](#privacy-and-security)
47
48
  - [Testing](#testing)
48
49
  - [Troubleshooting](#troubleshooting)
@@ -407,6 +408,17 @@ For local installation configuration, authentication options, and advanced techn
407
408
  - `query`: Search query string (e.g., "Injury Payouts pages", "active campaigns")
408
409
  - Returns: List of matching record IDs in ChatGPT-compatible format
409
410
 
411
+ ## Licensing
412
+
413
+ Meta Ads MCP is licensed under the [Business Source License 1.1](LICENSE), which means:
414
+
415
+ - ✅ **Free to use** for individual and business purposes
416
+ - ✅ **Modify and customize** as needed
417
+ - ✅ **Redistribute** to others
418
+ - ✅ **Becomes fully open source** (Apache 2.0) on January 1, 2029
419
+
420
+ The only restriction is that you cannot offer this as a competing hosted service. For questions about commercial licensing, please contact us.
421
+
410
422
  ## Privacy and Security
411
423
 
412
424
  Meta Ads MCP follows security best practices with secure token management and automatic authentication handling.
@@ -18,6 +18,7 @@ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for in
18
18
  - [Features](#features)
19
19
  - [Configuration](#configuration)
20
20
  - [Available MCP Tools](#available-mcp-tools)
21
+ - [Licensing](#licensing)
21
22
  - [Privacy and Security](#privacy-and-security)
22
23
  - [Testing](#testing)
23
24
  - [Troubleshooting](#troubleshooting)
@@ -382,6 +383,17 @@ For local installation configuration, authentication options, and advanced techn
382
383
  - `query`: Search query string (e.g., "Injury Payouts pages", "active campaigns")
383
384
  - Returns: List of matching record IDs in ChatGPT-compatible format
384
385
 
386
+ ## Licensing
387
+
388
+ Meta Ads MCP is licensed under the [Business Source License 1.1](LICENSE), which means:
389
+
390
+ - ✅ **Free to use** for individual and business purposes
391
+ - ✅ **Modify and customize** as needed
392
+ - ✅ **Redistribute** to others
393
+ - ✅ **Becomes fully open source** (Apache 2.0) on January 1, 2029
394
+
395
+ The only restriction is that you cannot offer this as a competing hosted service. For questions about commercial licensing, please contact us.
396
+
385
397
  ## Privacy and Security
386
398
 
387
399
  Meta Ads MCP follows security best practices with secure token management and automatic authentication handling.
@@ -7,7 +7,7 @@ with the Claude LLM.
7
7
 
8
8
  from meta_ads_mcp.core.server import main
9
9
 
10
- __version__ = "0.10.0"
10
+ __version__ = "0.10.2"
11
11
 
12
12
  __all__ = [
13
13
  'get_ad_accounts',
@@ -130,8 +130,9 @@ async def create_adset(
130
130
  promoted_object: Mobile app configuration for APP_INSTALLS campaigns. Required fields: application_id, object_store_url.
131
131
  Optional fields: custom_event_type, pixel_id, page_id.
132
132
  Example: {"application_id": "123456789012345", "object_store_url": "https://apps.apple.com/app/id123456789"}
133
- destination_type: Where users are directed after clicking the ad (e.g., 'APP_STORE', 'DEEPLINK', 'APP_INSTALL').
134
- Required for mobile app campaigns.
133
+ destination_type: Where users are directed after clicking the ad (e.g., 'APP_STORE', 'DEEPLINK', 'APP_INSTALL', 'ON_AD').
134
+ Required for mobile app campaigns and lead generation campaigns.
135
+ Use 'ON_AD' for lead generation campaigns where user interaction happens within the ad.
135
136
  access_token: Meta API access token (optional - will use cached token if not provided)
136
137
  """
137
138
  # Check required parameters
@@ -196,7 +197,7 @@ async def create_adset(
196
197
 
197
198
  # Validate destination_type if provided
198
199
  if destination_type:
199
- valid_destination_types = ["APP_STORE", "DEEPLINK", "APP_INSTALL"]
200
+ valid_destination_types = ["APP_STORE", "DEEPLINK", "APP_INSTALL", "ON_AD"]
200
201
  if destination_type not in valid_destination_types:
201
202
  return json.dumps({
202
203
  "error": f"Invalid destination_type: {destination_type}",
@@ -147,27 +147,16 @@ async def estimate_audience_size(
147
147
  }
148
148
  }, indent=2)
149
149
 
150
- # Build delivery estimate request
151
- endpoint = f"{account_id}/delivery_estimate"
150
+ # Build reach estimate request (using correct Meta API endpoint)
151
+ endpoint = f"{account_id}/reachestimate"
152
152
  params = {
153
- "targeting": targeting,
154
- "optimization_goal": optimization_goal
153
+ "targeting_spec": targeting
155
154
  }
156
155
 
157
- # Add basic campaign parameters for estimation
158
- if optimization_goal == "REACH":
159
- params["objective"] = "REACH"
160
- elif optimization_goal in ["LINK_CLICKS", "LANDING_PAGE_VIEWS"]:
161
- params["objective"] = "TRAFFIC"
162
- elif optimization_goal == "CONVERSIONS":
163
- params["objective"] = "CONVERSIONS"
164
- elif optimization_goal == "APP_INSTALLS":
165
- params["objective"] = "APP_INSTALLS"
166
- else:
167
- params["objective"] = "REACH" # Default fallback
156
+ # Note: reachestimate endpoint doesn't support optimization_goal or objective parameters
168
157
 
169
158
  try:
170
- data = await make_api_request(endpoint, access_token, params, method="POST")
159
+ data = await make_api_request(endpoint, access_token, params, method="GET")
171
160
 
172
161
  # Format the response for easier consumption
173
162
  if "data" in data and len(data["data"]) > 0:
@@ -191,14 +180,69 @@ async def estimate_audience_size(
191
180
  else:
192
181
  return json.dumps({
193
182
  "error": "No estimation data returned from Meta API",
194
- "raw_response": data
183
+ "raw_response": data,
184
+ "debug_info": {
185
+ "response_keys": list(data.keys()) if isinstance(data, dict) else "not_a_dict",
186
+ "response_type": str(type(data)),
187
+ "endpoint_used": f"{account_id}/reachestimate"
188
+ }
195
189
  }, indent=2)
196
190
 
197
191
  except Exception as e:
198
- return json.dumps({
199
- "error": f"Failed to get audience estimation: {str(e)}",
200
- "details": "Check targeting parameters and account permissions"
201
- }, indent=2)
192
+ # Check if this is the specific Business Manager system user permission error
193
+ error_str = str(e)
194
+ if "100" in error_str and "33" in error_str:
195
+ # Try to provide fallback estimation using individual interests if available
196
+ interests_found = []
197
+ if targeting and "interests" in targeting:
198
+ interests_found.extend([interest.get("id") for interest in targeting["interests"] if interest.get("id")])
199
+ elif targeting and "flexible_spec" in targeting:
200
+ for spec in targeting["flexible_spec"]:
201
+ if "interests" in spec:
202
+ interests_found.extend([interest.get("id") for interest in spec["interests"] if interest.get("id")])
203
+
204
+ if interests_found:
205
+ # Attempt to get individual interest data as fallback
206
+ try:
207
+ fallback_result = await estimate_audience_size(
208
+ access_token=access_token,
209
+ interest_fbid_list=interests_found
210
+ )
211
+ fallback_data = json.loads(fallback_result)
212
+
213
+ return json.dumps({
214
+ "comprehensive_targeting_failed": True,
215
+ "error_code": "100-33",
216
+ "fallback_used": True,
217
+ "details": {
218
+ "issue": "reachestimate endpoint returned error - possibly due to targeting parameters or account limitations",
219
+ "solution": "Individual interest validation used as fallback - comprehensive targeting may have specific requirements",
220
+ "endpoint_used": f"{account_id}/reachestimate"
221
+ },
222
+ "individual_interest_data": fallback_data,
223
+ "note": "Individual interest audience sizes provided as fallback. Comprehensive targeting via reachestimate endpoint failed."
224
+ }, indent=2)
225
+ except:
226
+ pass
227
+
228
+ return json.dumps({
229
+ "error": "reachestimate endpoint returned error (previously was incorrectly using delivery_estimate)",
230
+ "error_code": "100-33",
231
+ "details": {
232
+ "issue": "The endpoint returned an error, possibly due to targeting parameters or account limitations",
233
+ "endpoint_used": f"{account_id}/reachestimate",
234
+ "previous_issue": "Code was previously using non-existent delivery_estimate endpoint - now fixed",
235
+ "available_alternative": "Use interest_list or interest_fbid_list parameters for individual interest validation"
236
+ },
237
+ "raw_error": error_str
238
+ }, indent=2)
239
+ else:
240
+ return json.dumps({
241
+ "error": f"Failed to get audience estimation from reachestimate endpoint: {str(e)}",
242
+ "details": "Check targeting parameters and account permissions",
243
+ "error_type": "general_api_error",
244
+ "endpoint_used": f"{account_id}/reachestimate"
245
+ }, indent=2)
202
246
 
203
247
 
204
248
  @mcp_server.tool()
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meta-ads-mcp"
7
- version = "0.10.0"
8
- description = "Model Context Protocol (MCP) plugin for interacting with Meta Ads API"
7
+ version = "0.10.2"
8
+ description = "Model Context Protocol (MCP) server for interacting with Meta Ads API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  authors = [
@@ -3,7 +3,7 @@
3
3
  Unit tests for estimate_audience_size functionality in Meta Ads MCP.
4
4
 
5
5
  This module tests the new estimate_audience_size function that replaces validate_interests
6
- and provides comprehensive audience estimation using Meta's delivery_estimate API.
6
+ and provides comprehensive audience estimation using Meta's reachestimate API.
7
7
  """
8
8
 
9
9
  import pytest
@@ -58,14 +58,12 @@ class TestEstimateAudienceSize:
58
58
 
59
59
  # Verify API call
60
60
  mock_api.assert_called_once_with(
61
- "act_123456789/delivery_estimate",
61
+ "act_123456789/reachestimate",
62
62
  "test_token",
63
63
  {
64
- "targeting": targeting_spec,
65
- "optimization_goal": "REACH",
66
- "objective": "REACH"
64
+ "targeting_spec": targeting_spec
67
65
  },
68
- method="POST"
66
+ method="GET"
69
67
  )
70
68
 
71
69
  # Verify response format
@@ -80,7 +78,7 @@ class TestEstimateAudienceSize:
80
78
 
81
79
  @pytest.mark.asyncio
82
80
  async def test_different_optimization_goals(self):
83
- """Test audience estimation with different optimization goals"""
81
+ """Test audience estimation with different optimization goals (parameter is preserved in response)"""
84
82
  mock_response = {
85
83
  "data": [
86
84
  {
@@ -98,19 +96,13 @@ class TestEstimateAudienceSize:
98
96
  "geo_locations": {"countries": ["US"]}
99
97
  }
100
98
 
101
- test_cases = [
102
- ("REACH", "REACH"),
103
- ("LINK_CLICKS", "TRAFFIC"),
104
- ("LANDING_PAGE_VIEWS", "TRAFFIC"),
105
- ("CONVERSIONS", "CONVERSIONS"),
106
- ("APP_INSTALLS", "APP_INSTALLS"),
107
- ("UNKNOWN_GOAL", "REACH") # Should fallback to REACH
108
- ]
99
+ # Test different optimization goals - they should all use the same reachestimate endpoint
100
+ test_goals = ["REACH", "LINK_CLICKS", "LANDING_PAGE_VIEWS", "CONVERSIONS", "APP_INSTALLS"]
109
101
 
110
102
  with patch('meta_ads_mcp.core.targeting.make_api_request', new_callable=AsyncMock) as mock_api:
111
103
  mock_api.return_value = mock_response
112
104
 
113
- for optimization_goal, expected_objective in test_cases:
105
+ for optimization_goal in test_goals:
114
106
  mock_api.reset_mock()
115
107
 
116
108
  result = await estimate_audience_size(
@@ -120,16 +112,14 @@ class TestEstimateAudienceSize:
120
112
  optimization_goal=optimization_goal
121
113
  )
122
114
 
123
- # Verify correct objective mapping
115
+ # Verify API call uses reachestimate endpoint with simplified parameters
124
116
  mock_api.assert_called_once_with(
125
- "act_123456789/delivery_estimate",
117
+ "act_123456789/reachestimate",
126
118
  "test_token",
127
119
  {
128
- "targeting": targeting_spec,
129
- "optimization_goal": optimization_goal,
130
- "objective": expected_objective
120
+ "targeting_spec": targeting_spec
131
121
  },
132
- method="POST"
122
+ method="GET"
133
123
  )
134
124
 
135
125
  result_data = json.loads(result)
@@ -316,7 +306,7 @@ class TestEstimateAudienceSize:
316
306
 
317
307
  @pytest.mark.asyncio
318
308
  async def test_api_error_handling(self):
319
- """Test handling of API errors from delivery_estimate"""
309
+ """Test handling of API errors from reachestimate"""
320
310
  targeting_spec = {
321
311
  "age_min": 25,
322
312
  "age_max": 65,
@@ -338,12 +328,12 @@ class TestEstimateAudienceSize:
338
328
  assert "data" in result_data
339
329
  nested_data = json.loads(result_data["data"])
340
330
  assert "error" in nested_data
341
- assert "Failed to get audience estimation" in nested_data["error"]
331
+ assert "Failed to get audience estimation from reachestimate endpoint" in nested_data["error"]
342
332
  assert "details" in nested_data
343
333
 
344
334
  @pytest.mark.asyncio
345
335
  async def test_empty_api_response(self):
346
- """Test handling of empty response from delivery_estimate API"""
336
+ """Test handling of empty response from reachestimate API"""
347
337
  targeting_spec = {
348
338
  "age_min": 25,
349
339
  "age_max": 65,
@@ -614,7 +614,7 @@ class AudienceEstimationTester:
614
614
  print(f"\n✅ Audience estimation tests: SUCCESS ({passed_tests}/{total_tests} passed)")
615
615
  print(" • Comprehensive audience estimation is working")
616
616
  print(" • Backwards compatibility is maintained")
617
- print(" • Meta delivery_estimate API integration is functional")
617
+ print(" • Meta reachestimate API integration is functional")
618
618
  return True
619
619
  else:
620
620
  print(f"\n❌ Audience estimation tests: FAILED ({passed_tests}/{total_tests} passed)")
@@ -409,6 +409,57 @@ class TestMobileAppAdsetCreation:
409
409
  params = call_args[0][2]
410
410
  assert params['destination_type'] == "APP_INSTALL"
411
411
 
412
+ @pytest.mark.asyncio
413
+ async def test_on_ad_destination_type_for_lead_generation(
414
+ self, mock_api_request, mock_auth_manager, valid_mobile_app_params
415
+ ):
416
+ """Test ON_AD destination_type for lead generation campaigns (Issue #009 fix)"""
417
+
418
+ # Create a lead generation adset configuration (without promoted_object since it's for lead gen, not mobile apps)
419
+ lead_gen_params = valid_mobile_app_params.copy()
420
+ lead_gen_params.update({
421
+ "optimization_goal": "LEAD_GENERATION",
422
+ "billing_event": "IMPRESSIONS"
423
+ })
424
+
425
+ result = await create_adset(
426
+ **lead_gen_params,
427
+ destination_type="ON_AD"
428
+ )
429
+
430
+ # Should pass validation and include destination_type in API call
431
+ call_args = mock_api_request.call_args
432
+ params = call_args[0][2]
433
+ assert params['destination_type'] == "ON_AD"
434
+
435
+ @pytest.mark.asyncio
436
+ async def test_on_ad_validation_passes(
437
+ self, mock_api_request, mock_auth_manager, valid_mobile_app_params
438
+ ):
439
+ """Test that ON_AD destination_type passes validation (Issue #009 regression test)"""
440
+
441
+ # Use parameters that work with ON_AD (lead generation, not mobile app)
442
+ lead_gen_params = valid_mobile_app_params.copy()
443
+ lead_gen_params.update({
444
+ "optimization_goal": "LEAD_GENERATION",
445
+ "billing_event": "IMPRESSIONS"
446
+ })
447
+
448
+ result = await create_adset(
449
+ **lead_gen_params,
450
+ destination_type="ON_AD"
451
+ )
452
+
453
+ result_data = json.loads(result)
454
+
455
+ # Should NOT return a validation error about destination_type
456
+ # Before the fix, this would return: "Invalid destination_type: ON_AD"
457
+ if "data" in result_data:
458
+ error_data = json.loads(result_data["data"])
459
+ assert "error" not in error_data or "destination_type" not in error_data.get("error", "").lower()
460
+ else:
461
+ assert "error" not in result_data or "destination_type" not in result_data.get("error", "").lower()
462
+
412
463
  # Test: Error Handling
413
464
  @pytest.mark.asyncio
414
465
  async def test_meta_api_error_handling(
File without changes
File without changes
File without changes
File without changes
File without changes