I'm developing an API extension of our Woocommerce eshop. The task is to create a new Google Classroom user (if not yet existing) and add this user to the Course.
If the user does not exist yet, i create new:
$client = new Google_Client();
...
$service = new Google_Service_Directory($client);
...
$user = new Google_Service_Directory_User();
...
$service->users->insert($user);
Next step is to add the user to the course:
$client = new Google_Client();
...
$service = new Google_Service_Classroom($client);
$student = new Google_Service_Classroom_Student(['userId' => $studentId]);
...
$student = $service->courses_students->create($courseId, $student);
I found out I have to wait for ~30s between these two tasks. If i do this earlier, the API cannot see the user ("Requested entity was not found.").
The code is working normally, if I run it after 30s, or if the user allready exists and only enrollment is called..
Is this expected behaviour? Do i have to wait 30s to be able to work with the created user?
A 30s waiting is normal, sometimes it can take even more time. Even if the request is created through API, it's still affected by the propagation time while using the Admin Console.
I have experience, even a 24 hours delay for all the services to be enabled for 1 user. For example: I created a user, and after a few minutes I can send emails from it, but I cannot create a calendar event. You can review more information about this in the Google Documentation here. Where is states: