Skip to content

fix: AdReportRun can't retain id with post insights#151

Open
mktktmr wants to merge 2 commits into
facebook:mainfrom
mktktmr:feature/asynchronous_insights
Open

fix: AdReportRun can't retain id with post insights#151
mktktmr wants to merge 2 commits into
facebook:mainfrom
mktktmr:feature/asynchronous_insights

Conversation

@mktktmr

@mktktmr mktktmr commented Aug 13, 2021

Copy link
Copy Markdown
Contributor

I'd like to use AdReportRun like below.

ad_account = FacebookAds::AdAccount.get(some_params)

# Generating a job to create report
ad_report_run = ad_account.insights.create(some_params)

# Waiting until the job completed
until ad_report_run.reload! && ad_report_run.async_status == "Job Completed"
  sleep 1
end

# Fetching the report
ad_report_run.insights.all

Unfortunately AdReportRun causes an error with api request in reality, because AdReportRun has report_run_id instead of id. As you know AdObject (and its sub class) try to get data by id.

ad_account = FacebookAds::AdAccount.get(some_params)

ad_report_run = ad_account.insights.create(some_params)

ad_report_run.async_status # error occurred
# => NoMethodError: undefined method `gsub' for nil:NilClass
#    from /usr/src/tmp/facebook-ruby-business-sdk/lib/facebook_ads/session.rb:41:in `request'

That's why I added a process to replace attributes report_run_id to id on AdObject#initialize.

@mktktmr mktktmr force-pushed the feature/asynchronous_insights branch from 18fbad6 to 78db8c0 Compare August 13, 2021 12:45
@mktktmr mktktmr marked this pull request as ready for review August 13, 2021 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants