Google Analytics Management API - 'Unknown name "": Root element must be a message' when I try to update Google Analytics view

Viewed 155

I have been struggling with this for a bit, but I am trying to find a programmatic way to update the Google Analytics views and change the name for all of the views. As a test, I wanted to start small and focus on only one views. Using App Script Console, I wrote this code:

function update_views() {
  var view_id = "11545xxxx";
  
  var payload = {"Name":"Updated .ca View"}
  var payload_str = payload.toString();
  //Logger.log(payload_str)
  var profile = Analytics.Management.Profiles.update("xxxxx","UA-xxxxx-49","11545xxxx",payload_str)

}

But when I try to execute the function, I get the following error

GoogleJsonResponseException: API call to analytics.management.profiles.update failed with error: Invalid JSON payload received. Unknown name "": Root element must be a message. update_views @ update_views.gs:7

I even tried sending the data as an object and not a string, but the same end result.

Does anyone know what can be done?

1 Answers

This is seems quite confusing to me from api documentation. Try to add the payload first something like

var profile = Analytics.Management.Profiles.update(payload_str,"xxxxx","UA-xxxxx-49","11545xxxx")}

This should fix the error you are getting.

Related