Skip to content

Commit

Permalink
source-facebook-marketing: validate account ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Bair committed Nov 22, 2024
1 parent f9e3e79 commit e9c337b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Videos,
)

from .utils import validate_end_date, validate_start_date
from .utils import validate_end_date, validate_start_date, validate_account_ids

logger = logging.getLogger("airbyte")
UNSUPPORTED_FIELDS = {"unique_conversions", "unique_ctr", "unique_clicks",
Expand Down Expand Up @@ -96,6 +96,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Type[Stream]]:

api = API(access_token=config.credentials.access_token)

validate_account_ids(api, config.account_ids)

insights_args = dict(
api=api, start_date=config.start_date, end_date=config.end_date, insights_lookback_window=config.insights_lookback_window, account_ids=config.account_ids,
)
Expand Down
16 changes: 16 additions & 0 deletions source-facebook-marketing/source_facebook_marketing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#

import logging
from typing import List

import pendulum
from pendulum import DateTime
from estuary_cdk.flow import ValidationError

from source_facebook_marketing.api import API, FacebookAPIException

logger = logging.getLogger("airbyte")

Expand Down Expand Up @@ -45,3 +49,15 @@ def validate_end_date(start_date: DateTime, end_date: DateTime) -> DateTime:
logger.warning(message)
return start_date
return end_date

def validate_account_ids(api: API, account_ids: List[str]):
errs = []
for account_id in account_ids:
try:
api._find_account(account_id)
except FacebookAPIException as err:
msg = f"Error when validating account ID {account_id}: {err}"
errs.append(msg)

if len(errs) > 0:
raise ValidationError(errs)

0 comments on commit e9c337b

Please sign in to comment.