googleads/googleads-dfa-reporting-samples

Report / update Criteria - set DateRange / relative_date_range value? issue?

Closed this issue · 2 comments

DateRange dateRange = new DateRange();

dateRange.setEndDate(new DateTime(true, System.currentTimeMillis(), null));

Calendar lastMonth = Calendar.getInstance();
lastMonth.add(Calendar.MONTH, -1);
dateRange.setStartDate(new DateTime(true, lastMonth.getTimeInMillis(), null));

// Create a report criteria.
Report.Criteria criteria = new Report.Criteria();
criteria.setDateRange(dateRange);

// Add the criteria to the report resource.
Report report = new Report();
report.setCriteria(criteria);

Report patchedReport = reporting.reports().patch(profileId, reportId, report).execute();

{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Both relative_date_range and start or end cannot be set in date range.",
"reason" : "invalid"
} ],
"message" : "Both relative_date_range and start or end cannot be set in date range."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.api.services.samples.dfareporting.reports.RunReport.runExample(RunReport.java:63)
at com.google.api.services.samples.dfareporting.reports.RunReport.main(RunReport.java:122)

Hi there,

This is expected behavior if the report already has a relative date range configured. Patch will only affect the fields you explicitly specify in the request. To switch from a relative to custom date range, you'd need to unset the existing relative date range in addition to what you're already doing.

Note that since the relative date is specified as a string, you'll need to use the magic null string object to clear it out, due to the way the Java HTTP library handles null values:

dateRange.setRelativeDateRange(Data.NULL_STRING);

Regards,

  • Jonathon Imperiosi, DCM API Team

This error seems to still occur as of today, with the payload below

{
  "endDate": "2023-08-02",
  "kind": "dfareporting#dateRange",
  "relativeDateRange": null,
  "startDate": "2023-07-30"
}

If an offline report has a relative date set beforehand, it looks to be impossible to undo it strictly via the API.