Search code examples
pythongoogle-apps-scriptgoogle-analytics-api

Values must match the following regular expression: '\d+' error


I'm trying to build a small Google App Script with Google Analytics API management to copy Google Analytics filters from one view to another.

I've the following python snippet which I'd like to translate into Google App Script:

# This request creates a new profile filter link.
try:
  analytics.management().profileFilterLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      profileId='7654321',
      body={
          'filterRef': {
              'id': '1223334444'
          }
      }
  ).execute()

I'm able to get a list of profile filter link like this:

var filterLinks = Analytics.Management.ProfileFilterLinks.list(
      '12345678','UA-98765432-1','111111111')

I tried to replicate something similar with for the insert method but It doesn't work:

var body = JSON.stringify({
         'filterRef': {
             'id': '84029058'
}});

var up = Analytics.Management.ProfileFilterLinks.insert('12345678','UA-98765432-1','111111111',body)

any idea?


Solution

  • How about this answer?

    Modification points:

    • At Advanced Google services, the arguments of Analytics.Management.ProfileFilterLinks.insert() are resource, accountId, webPropertyId, profileId.
    • In your python script, you are using the following values as the arguments of analytics.management().profileFilterLinks().insert().

      accountId='123456',
      webPropertyId='UA-123456-1',
      profileId='7654321',
      body={'filterRef': {'id': '1223334444'}}
      
      • In this case, resource, accountId, webPropertyId, profileId are body, accountId, webPropertyId, profileId, respectively.

    So how about the following modification?

    Modified script:

    var resource = {filterRef: {id: '1223334444'}};
    var accountId = '123456';
    var webPropertyId = 'UA-123456-1';
    var profileId = '7654321';
    var up = Analytics.Management.ProfileFilterLinks.insert(resource, accountId, webPropertyId, profileId);
    

    Note:

    • Please confirm whether the values of resource, accountId, webPropertyId, profileId are correct, again.

    Reference: