0

Is there a way to make the insert and assignment of a user to a group a single, unit operation with the Admin SDK API? Currently I have to make separate calls to directory.users().insert(<user>).execute() and directory.members().insert(<groupKey>, <member>).execute().

I think there's a problem with this approach because one operation can complete successfully and the other not. So the user is inserted, but is not assigned to any group. It would be nice if we could specify the group information along with the user information when we insert the user.

Is there a way to do this?

abraham
  • 46,583
  • 10
  • 100
  • 152
Marcos
  • 1,237
  • 1
  • 15
  • 31
  • I don't think you can combine both the requests. You can add group to a member, after he/she is inserted as user. That is the reason there are two separate requests. You cannot add group while inserting user. – SGC May 18 '15 at 17:57
  • Yes, I know it. I just regret this as I have to put catch blocks in my code to try to delete the just recent inserted user if the group operation fails. And even with this some error may occur in the catch block and the user stays without being added to a group. That's the problem with non-atomic operations or with the lack of a way to simulate something like relational database transactions. A group is an inherent property of a user. There should be a way to insert the two as one, as well as alone (the way we have today). – Marcos May 18 '15 at 18:17

1 Answers1

0

Sorry, this isn't an atomic API. There's an expectation that some operations will fail and your code needs to handle that. You can implement exponential backoff and retry to ensure temporary failures are handled. Your code should also be prepared for permanent failure errors and deal with these situations appropriately.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • Thank you for the answer. At least I know that there's nothing to do in this case but to prepare my code to deal with errors. – Marcos May 19 '15 at 15:58