2

I have been using App Scripts to Download and insert CM360 reports into Google Sheets for a while now, but since a couple of days back I get the following error when running the code:

Exception: Unexpected error: https://www.googleapis.com/dfareporting/v3.4/reports/xxx/files/xxx?alt=media (Code:23:56)

Example of the code I am running:

function runreport() {
var reportId = xxx;
var profileId = xxx;
var additionalParameters = {'synchronous': 'true'};

var ReportFile = DoubleClickCampaigns.Reports.Files.list(profileId,reportId);
var ReportFileID = (ReportFile.items[0].id);
var newReportFile = DoubleClickCampaigns.Files.get(reportId, ReportFileID);

if(newReportFile.urls) {var httpOptions = {'headers': {'Authorization':'Bearer ' + ScriptApp.getOAuthToken()}};
var csvContent = UrlFetchApp.fetch(newReportFile.urls.apiUrl, httpOptions).getContentText();
var csvData = Utilities.parseCsv(csvContent);}}

Do anyone else encountered this issue and have managed to solve it?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
AR_379402
  • 21
  • 3
  • What do you mean by "When looking into the URL"? – TheMaster Dec 11 '20 at 08:27
  • This URL: https://www.googleapis.com/dfareporting/v3.4/reports/xxx/files/xxx?alt=media that is pushed form the response in App Scripts. However, I realise now that the response from just that URL, when inserted into a browser, will provide a auth error since I have not inserted the header/auth into the call. – AR_379402 Dec 11 '20 at 09:18
  • @AR Yes, So the 401 is irrelevant and the only part relevant is the "Unexpected error" – TheMaster Dec 11 '20 at 09:27
  • You might wanna [edit] the question to reflect that. Also, this is better addressed by Google. Create a issue in the issuetracker and add the link to the issue here as a answer. See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for more details. – TheMaster Dec 11 '20 at 09:34
  • Yes, I have edited the question and will create an issue in the issuetracker! Thanks! – AR_379402 Dec 11 '20 at 09:37
  • This question was undeleted as the answer is useful and significant efforts were made by others, who contributed. If you don't want to be associated with this question, you can [flag] your own question for moderator intervention to remove your name from this question. – TheMaster Dec 12 '20 at 04:34

1 Answers1

2

The unexpected error is due to a new bug with UrlFetchApp

It has already been filed serveral times, e.g. here.

So instead of filing it again you should rather "star" the already existing issue - to increase its visibility.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33