0

Hi everyone and thanks for your help.

I try to figure it out an APpsScript code/function that allows me to pull the stats (Error rate, Executions, Users) from the "Project Dashboard" and store it into a Google sheet in three different columns.

I hope anyone can help me since I have to monitor several projects.

In the past, I logged the info for each project separately but now there would be too many projects.

Angel A
  • 11
  • 2
  • Welcome to Stack Overflow! It's difficult to tell what is being asked here, and this question cannot be reasonably answered in its current form. Please provide the context, and/or post code samples of what you have done (i.e.: [What have you tried?](http://whathaveyoutried.com)) – Miroslav Glamuzina Mar 31 '19 at 02:14
  • 1
    I'd be interested in what you've tried so far. I've looked at the Google Apps Script Rest API under [Projects.getMetrix](https://developers.google.com/apps-script/api/reference/rest/v1/projects/getMetrics) but I haven't had the time to really dig into it much. There are so many API's to learn about. – Cooper Mar 31 '19 at 02:45

1 Answers1

1

Thank you Miroslav Glamuzina & Cooper for your replies.

Cooper thanks to your comment and link I was able to pull the information that I needed from the metrics, so in order to help any other person in the future here is the code that I used:

function getMetrics(){        
        var projectID ="<ENTER_YOUR_PROJECT_ID>";
        var tokenAPI = "<ENTER_YOUR_BEARER_TOKEN>";

        var api = "https://script.googleapis.com/v1/projects/" + projectID + "/metrics";
        var query = "?metricsGranularity=WEEKLY";
        var headers = { "Accept": "application/json", "Authorization": "Bearer " + tokenAPI };
        var options = {
            method: "GET",
            contentType: "application/json",
            headers: headers,
            muteHttpExceptions: true
        };

        var response = UrlFetchApp.fetch(api + query, options);
        var json = response.getContentText();
        var data = JSON.parse(json);

        Logger.log(data)
};

I got the results from the JSON and everything was good to be applied in any place that I needed. Once again thank you to point me in the right direction.

Angel A
  • 11
  • 2