Unable to update stream permissions or bulk invite from GH custom node

Hi @jonathon ,

I try to use this, but I’m stuck on eighter way.

If I use GH_CPython I got this message:
SpeckleException: Failed to execute the GraphQL stream request. Inner exception: SpeckleException: Method execute is not supported by the SpeckleClient class

If I try to make a Grasshopper component in C# I get one of these:
Exception: Your request failed on the server side
Exception: Request failed with errors

Do you have any idea what can be the issue?

@reka you are inviting users to a project from Grasshopper?

There is not a lot to go on here, can you share actual code?

Is this for a hackathon entry?

@jonathon ,
yes, I would like to invite people from Grasshopper. The idea is for the hackathon, yes.

So this is the body of my code in C#


        protected override void SolveInstance(IGH_DataAccess DA)
        {

            string ghSpeckleStream = null;
            string ghSpeckleLink = null;
            var collaborators = new List<string>();
            var roles = new List<string>();
            Speckle.Core.Api.Stream stream = new Speckle.Core.Api.Stream();


            if (!DA.GetData(0, ref ghSpeckleStream))
            {
                return;
            }
            DA.GetData(1, ref ghSpeckleLink);
            DA.GetDataList(2, collaborators);
            DA.GetDataList(3, roles);


            var streamWrapper = new StreamWrapper(ghSpeckleStream);

            var collaborator = collaborators[0];
            var role = roles[0];

            Task.Run(async () =>
            {
                try
                {
                    var account = await streamWrapper.GetAccount();
                    var client = new Client(account);

                    var updatePermissionInput = new StreamPermissionInput
                    {
                        streamId = ghSpeckleLink,
                        userId = collaborator,
                        role = role
                    };
                    
                    await client.StreamUpdatePermission(updatePermissionInput);
                    
                }
                catch (Exception exception)
                {
                    DA.SetData(1, $"{nameof(Exception)}: {exception.Message}");
                }
            }).Wait();
            //            }
            
                        Task.Run(async () =>
                        {
                            var account = await streamWrapper.GetAccount();
                            var client = new Client(account);
                            stream = await client.StreamGet(ghSpeckleStream);


                        }).Wait();
            
            DA.SetDataList(0, stream.collaborators);
        }

It fails on this line:

await client.StreamUpdatePermission(updatePermissionInput);

and this is my python code:


from specklepy.api.client import SpeckleClient
from specklepy.api.credentials import get_account_from_token
from specklepy.api.wrapper import StreamWrapper as sw
from specklepy.api.resources.stream import Resource as rs



wrapper = sw(stream_link)
print (wrapper)

client = wrapper.get_client() 
print (client)


account = get_account_from_token("MY_TOKEN", wrapper.server_url)
print (account)
client.authenticate_with_account(account)


resource = rs(account,wrapper.server_url,client, (2,18,17))
print (resource)
print ("  ")

update = rs.update_permission(resource, stream, user, role)
print (update)

At least here I’m pretty sure the issue is with the resource although this server version format was the only way I could find out where it was not telling me that it cannot compare text to touple. (MY_TOKEN is my token, so autentication goes well)

The C# code interestingly fails differently, if I provide input differently. So if the input is:

strteam: ID
user: ID
role: owner

The message is:

Exception: Request failed with errors

And with these inputs:

strteam: https://speckle.xyz/streams/ID
user: ID
role: stream:contributor

This is the message:

Exception: Your request failed on the server side

Hey there, currently taking a look and rousing others :slight_smile:

Thank you for all of your hard work :slightly_smiling_face:

Are you able to expand and see the errors part of the response? I think there should be an errors property in the response. They should point us in the right way.
Also, are you the owner of such stream/project?

Both the request (GraphQL query) and the response would be useful to see

Hi @teocomi and @fabians ,

I have a hard time gathering more information about the error. This is what I see in the debug output:

onecore\net\netprofiles\service\src\nsp\dll\namespaceserviceprovider.cpp(613)\nlansp_c.dll!00007FF84DDFF6DD: (caller: 00007FF88518ACF6) LogHr(92) tid(1504) 8007277C Nincs ilyen ismert szolgáltatás. A szolgáltatás nem található a megadott névtérben.
Exception thrown: 'Speckle.Core.Api.SpeckleGraphQLException`1' in SpeckleCore2.dll
Exception thrown: 'Speckle.Core.Api.SpeckleGraphQLException`1' in System.Private.CoreLib.dll
Exception thrown: 'Speckle.Core.Api.SpeckleGraphQLException`1' in Polly.dll

I think the role should be formatted as stream:owner, see here an example integration test for this API call:

Hi @teocomi ,

I’ve tried this and the result is the same as I wrote before. ( Exception: Your request failed on the server side)

Can you maybe help me how to extract the GraphQL query request and response?

And yes, I’m the owner of the stream.

Hi @teocomi and all,

I found the issue. It might be obvious for you, but clearly wasn’t for me. :sweat_smile:
You have to invite the user first, than accept the invite, than you can update the role. I skipped the first two steps.
Thank you all.

Btw if you have any idea how to do it in one step, it would be great to know.

1 Like

Hey @reka

changing users roles without them being part of a (stream) project is not supported any more. You need to invite the users to the specific project beforehand and the need to accept the invite before you can change their role from a script.

For spam protection reasons, we do not allow sending invites via api tokens, so unfortunatelly you cannot do this from a GH script.

You can however bulk invite users from the project collaborators page. You can even paste in a comma separated list of emails to invite to the project if that is useful.

Sorry for not being clear about this sooner.

Gergő

3 Likes