Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

existing pricing period Data Truncation when adding new pricing periods to the existing placement #114

Open
datadogcoder opened this issue Oct 9, 2024 · 0 comments

Comments

@datadogcoder
Copy link

Hi Team

I am facing a existing pricing period data truncation issue when inserting a new pricing period row using DCM API.

NOTE: The github code reference link does not have placement.Patch method usage.
This pricing insert is working fine when using google API explorer. What is the problem with my code?
def create_pricing_period(pricing):
try:
return {
'startDate': pricing['pricingperiodstartdate'],
'endDate': pricing['pricingperiodenddate'],
'units': pricing['units'],
'rateOrCostNanos': int(float(pricing['rateorcostnanos']) * 1e9),
'pricingComment': pricing['pricingcomment']
}
except ValueError as e:
print(f"Error converting rateOrCostNanos: {e}")
return None

def patch_pricing_period_to_placement(campaign_id, placement_id, site_id, new_pricing_period):
    try:
        placement = dfa_service.placements().get(profileId=profile_id, id=placement_id).execute()
        print("current placement data",placement)

        pricing_schedule = placement.get('pricingSchedule', {})
        pricing_periods = pricing_schedule.get('pricingPeriods', [])
        print("Old pricing period", pricing_periods)
        # Directly append new pricing period without validation
        #pricing_periods.append(new_pricing_period)
        print("New pricing period", new_pricing_period)

     ```

Update body aligned with provided structure

        update_body = {
            'pricingSchedule': {
                'pricingPeriods': new_pricing_period
            }
        }
            placement.update(update_body)
            updated_placement = dfa_service.placements().patch(
                profileId=profile_id,
                id=placement_id,
                body=update_body
            ).execute()
            # updated_placement = dfa_service.placements().update(
            #     profileId=profile_id,
            #     body=placement
            # ).execute()
            # get an updated copy of data - test this on monday ???
            # placement.update(updated_placement)
            print(f"New pricing period added successfully: {updated_placement}")

        except Exception as e:
            print(f"An error occurred while patching pricing period: {e}")

    print(pricing_schedule_df.columns)
    for _, pricing in pricing_schedule_df.iterrows():
        print(pricing)
        campaign_id = pricing['campaignid']
        placement_id = pricing['placementid']
        site_id = pricing['siteid']
        print(f"Processing CampaignID: {campaign_id}, PlacementID: {placement_id}, SiteID: {site_id}")

        matching_campaign = find_matching_campaign_placement(campaign_id, placement_id, site_id)

        if matching_campaign is not None:
            new_pricing_period = create_pricing_period(pricing)

            if new_pricing_period:
                patch_pricing_period_to_placement(campaign_id, placement_id, site_id, new_pricing_period)
                # placement = dfa_service.placements().get(profileId=profile_id, id=placement_id).execute()

        else:
            print(f"No matching campaign found for CampaignID: {campaign_id}, PlacementID: {placement_id}, SiteID: {site_id}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant