Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Implementing User Permissions Management with GA4 Admin API and Apps Script › Reply To: Implementing User Permissions Management with GA4 Admin API and Apps Script
-
The error message you received, “The value for the ‘direct_roles’ field was empty, but must be provided” suggests that the ‘direct_roles’ field in your request does not have a value when you are trying to add a new user. The ‘direct_roles’ field is expected to contain the roles that you want to assign to the user you’re adding.
Considering the request body you’re using, it seems like you’re reading the roles from ‘entity[6]’ which appears to be an array. You need to ensure that ‘entity[6]’ contains the role or roles you want to assign to the user. It could be that ‘entity[6]’ is empty or undefined when you’re building your request, hence resulting in the error.
In short, you need to make sure you’re providing valid roles in ‘entity[6]’ when building the request. You could add some checks or validations in your code to make sure ‘entity[6]’ is not empty or undefined before building the request, and that should resolve the 400 error.