Account User Links: insert API not working for permissions : "Manage Users" and "Read & Analyze"

614 views
Skip to first unread message

satyap...@aonhewitt.com

unread,
Dec 4, 2013, 5:48:18 AM12/4/13
to google-analytic...@googlegroups.com
Hi,

I am using Management API to insert a new user to Google Accounts but i am getting below error.It works fine though for "EDIT" and "Collaborate".

The issue comes when using the API programatically as well as when i use the link https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountUserLinks/insert



400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Field permissions is required."
}
],
"code": 400,
"message": "Field permissions is required."
}
}

Posting the request as well

POST https://www.googleapis.com/analytics/v3/management/accounts/41011686/entityUserLinks?fields=permissions%2CuserRef&key={YOUR_API_KEY}

Content-Type:  application/json
Authorization:  Bearer ya29.1.AADtN_U_rzDq7M5Xo4p31vskkFbed2SOlFyLFg6_N7xgb_MBD9IKfGJl8E5Y-Qe67_JJOnp1
X-JavaScript-User-Agent:  Google APIs Explorer
{
"permissions": {
"effective": [
"MANAGE USERS"
],
"local": [
"MANAGE USERS"
]
},
"userRef": {
}
}


Thanks
Satyapal

satyap...@aonhewitt.com

unread,
Dec 5, 2013, 3:16:17 AM12/5/13
to google-analytic...@googlegroups.com
Hi,

This came out to be non issue.
When i passed MANAGE_USERS and READ_AND_ANALYZE as permission i was able to add the user.

However it would have helped if it was mentioned somewhere.

Thanks

dan...@orng.es

unread,
Dec 10, 2013, 12:12:02 AM12/10/13
to google-analytic...@googlegroups.com
Yeah. GA management api documentation is lil incomplete, i had many problems with Management API but i am good to go. 


On Wednesday, December 4, 2013 4:18:18 PM UTC+5:30, satyap...@aonhewitt.com wrote:

Léo Goffic

unread,
Jan 31, 2014, 1:20:38 PM1/31/14
to google-analytic...@googlegroups.com
Hi,

I am having the same issue trying to create a webpropertyUserLink with `READ_AND_ANALYZE` permission. Sadly, adding `MANAGE_USERS` didn't help and I am still seeing a 400 response with "Field permissions is required".

Any idea? Am I missing something?

Thanks

Alun Hewinson

unread,
Feb 1, 2014, 3:14:51 PM2/1/14
to google-analytic...@googlegroups.com
Hi Léo,

Can you post the JSON string you are trying to submit?  I had the same error message when I was trying to submit some JSON which was constructed wrong.  I will look at it and see if I can spot a problem there.
(You might want to consider editing the real account id, webproperty id and email address text to keep them private, before you paste it onto this forum.)

Regards,
Alun Hewinson
Netbooster

NetBooster Affiliate is a subsidiary of NetBooster Holding A/S and NetBooster SA. This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please contact us. The content of this email does not necessarily reflect the views or opinions of NetBooster Affiliate.

Léo Goffic

unread,
Feb 3, 2014, 9:15:10 AM2/3/14
to google-analytic...@googlegroups.com
Hi Alun,

Sure, here is the (nodejs) code I used to make my tests:

```
analyticsApiClient
        .management
        .webpropertyUserLinks
        .insert({
          accountId: accountId, // Numerical accountId
          webPropertyId: webpropertyId // UA-string
        }, {
          userId: userId, // Numerical User ID from Google
          permissions: {
            effective: ["READ_AND_ANALYZE"],
            local: []
          }
        });
```

```
{
  "userId" : "_",
  "permissions" : ["READ_AND_ANALYZE"]
}
```

I tried to pass `{ "userRef": { "email": "_" } }` instead of the userId, but it failed with the same message.

Thanks for your help,

Léo

Alun Hewinson

unread,
Feb 3, 2014, 9:53:00 AM2/3/14
to google-analytic...@googlegroups.com
Hi

The JSON isn't structured correctly.  Here is a possible correction:

{
 "permissions": {
    "local": [ "READ_AND_ANALYZE" ]
 },
 "userRef": {
    "id": "_",
    "email": "_",
    "kind": "analytics#userRef"
    }
}

In other words, the "permissions" section needs to be surrounded by {curly brackets}.  The same applies to the userRef section, and it applies even if you only have one items within that.  I don't know the software you are using to generate the JSON code, but it might be an idea to use the "Try It!" section towards the bottom of the help page https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webpropertyUserLinks/insert to get a JSON body that definitely works.  Then see if you can submit that as a post request*, then lastly see if you can get your software to build the full thing, creating the correct JSON body and submitting it through POST.

Please note that I am quite new to this myself, so I don't know if you're also supposed to include the "entity" section.  But if you get it working on the Try It! section, then that will tell you that you have enough information in the JSON body.

*if you try to insert permissions for a user who has already been added, you will receive a 400 error "The user is already on the enitty"[sic]; if so you should try a different user or manually remove their permissions first.

If you do get it working, please post your (redacted) JSON body here, so others can benefit from your experience :)

Alun

Alun Hewinson

unread,
Feb 10, 2014, 5:55:08 AM2/10/14
to google-analytic...@googlegroups.com
Hi Léo,

How did you get on with this?  Is it working now?  If so, please post back your code to help others.  If not, let us know what you have tried and if you're getting the same error message.

Cheers,
Alun

Léo Goffic

unread,
Feb 16, 2014, 11:33:40 AM2/16/14
to google-analytic...@googlegroups.com
Hi Alun,

I indeed managed to get it to work by following your advices. Here is the final code I am using:

```
analyticsApiClient
        .management
        .webpropertyUserLinks
        .insert({
          accountId: accountId, // Numerical accountId
          webPropertyId: webpropertyId // UA-string
        }, {
          userRef: {
            email: email, // User email
            kind: "analytics#userRef"
          },
          permissions: {
            local: ["READ_AND_ANALYZE"]
          }
        });
```

which translates to the matching call to their API.

Thanks for your help!

Cheers,

Léo
Reply all
Reply to author
Forward
Message has been deleted
0 new messages