@@ -127,7 +127,7 @@ var groupCreateTokenCmd = &cobra.Command{
127127 if err != nil {
128128 return err
129129 }
130- token , err := client . Groups . Token ( group . Name , expiration , flags .ReadOnly (), claim , permission )
130+ token , err := getGroupToken ( client , group , expiration , flags .ReadOnly (), claim , permission )
131131 if err != nil {
132132 return fmt .Errorf ("error creating token: %w" , err )
133133 }
@@ -137,6 +137,37 @@ var groupCreateTokenCmd = &cobra.Command{
137137 },
138138}
139139
140+ // getGroupToken creates a group token, using the V3 API when enabled and the
141+ // org/group IDs can be resolved. The V3 endpoint does not support attach
142+ // claims, so requests with a claim fall back to the V2 API.
143+ func getGroupToken (
144+ client * turso.Client ,
145+ group turso.Group ,
146+ expiration string ,
147+ readOnly bool ,
148+ claim * turso.PermissionsClaim ,
149+ fineGrainedPermissions []flags.FineGrainedPermissions ,
150+ ) (string , error ) {
151+ if ! flags .V3Api () || claim != nil {
152+ return client .Groups .Token (group .Name , expiration , readOnly , claim , fineGrainedPermissions )
153+ }
154+ orgID , err := tryResolveOrgID (client )
155+ if err != nil {
156+ return "" , err
157+ }
158+ groupID := group .UUID
159+ if groupID == "" {
160+ groupID , err = tryResolveGroupID (client , group .Name )
161+ if err != nil {
162+ return "" , err
163+ }
164+ }
165+ if orgID == "" || groupID == "" {
166+ return client .Groups .Token (group .Name , expiration , readOnly , claim , fineGrainedPermissions )
167+ }
168+ return client .GroupsV3 .Token (orgID , groupID , expiration , readOnly , fineGrainedPermissions )
169+ }
170+
140171func validateDBNames (client * turso.Client , dbNames []string ) error {
141172 databasesMap , err := getDatabasesMap (client , false )
142173 if err != nil {
0 commit comments