Control access to your account

The Merchant API lets you programmatically manage who can access your Merchant Center account, and their access rights. This is essential for maintaining security and verifying that individuals have appropriate access to perform their roles, whether it's managing products, viewing reports, or administering the account. You can add users, update their access rights, view current users, and remove users who no longer need access.

When managing user access, it is important to adhere to the principle of least privilege, verifying that users are granted only the minimum necessary access rights required to perform their specific roles, and no more.

When you add a user, they receive an invitation and, upon acceptance, can access your Merchant Center account with the access rights you've granted. You can find more information about managing people and their access rights at I need help with people and access levels .

Supported features

  • Create
  • Delete
  • Get
  • List
  • Update

You can retrieve a list of all users who have access to your Merchant Center account. This is useful for auditing access and understanding current user access rights. The response will include each user's email and their assigned access rights.

This corresponds to the users.list method.

  GET https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users 
 

A successful request returns a 200 OK HTTP status code and a response body with the list of User resources:

  { 
  
 "users" 
 : 
  
 [ 
  
 { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/user1@example.com" 
 , 
  
 "state" 
 : 
  
 "VERIFIED" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "ADMIN" 
  
 ] 
  
 }, 
  
 { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/user2@example.com" 
 , 
  
 "state" 
 : 
  
 "VERIFIED" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "STANDARD" 
 , 
  
 "PERFORMANCE_REPORTING" 
  
 ] 
  
 } 
  
 ] 
 } 
 

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.ListUsersRequest 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.User 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient.ListUsersPagedResponse 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to list all the users for a given Merchant Center account. */ 
 public 
  
 class 
 ListUsersSample 
  
 { 
  
 private 
  
 static 
  
 String 
  
 getParent 
 ( 
 String 
  
 accountId 
 ) 
  
 { 
  
 return 
  
 String 
 . 
 format 
 ( 
 "accounts/%s" 
 , 
  
 accountId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 listUsers 
 ( 
 Config 
  
 config 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 UserServiceSettings 
  
 userServiceSettings 
  
 = 
  
 UserServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates parent to identify the account from which to list all users. 
  
 String 
  
 parent 
  
 = 
  
 getParent 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 UserServiceClient 
  
 userServiceClient 
  
 = 
  
 UserServiceClient 
 . 
 create 
 ( 
 userServiceSettings 
 )) 
  
 { 
  
 // The parent has the format: accounts/{account} 
  
 ListUsersRequest 
  
 request 
  
 = 
  
 ListUsersRequest 
 . 
 newBuilder 
 (). 
 setParent 
 ( 
 parent 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending list users request:" 
 ); 
  
 ListUsersPagedResponse 
  
 response 
  
 = 
  
 userServiceClient 
 . 
 listUsers 
 ( 
 request 
 ); 
  
 int 
  
 count 
  
 = 
  
 0 
 ; 
  
 // Iterates over all rows in all pages and prints the user 
  
 // in each row. 
  
 // `response.iterateAll()` automatically uses the `nextPageToken` and recalls the 
  
 // request to fetch all pages of data. 
  
 for 
  
 ( 
 User 
  
 element 
  
 : 
  
 response 
 . 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 element 
 ); 
  
 count 
 ++ 
 ; 
  
 } 
  
 System 
 . 
 out 
 . 
 print 
 ( 
 "The following count of elements were returned: " 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 count 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 listUsers 
 ( 
 config 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Accounts\V1\ListUsersRequest; 
 use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient; 
 /** 
 * Lists users. 
 * 
 * @param array $config The configuration data. 
 * @return void 
 */ 
 function listUsers($config): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $userServiceClient = new UserServiceClient($options); 
 // Creates parent to identify the account from which to list all users. 
 $parent = sprintf("accounts/%s", $config['accountId']); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new ListUsersRequest(['parent' => $parent]); 
 print "Sending list users request:\n"; 
 $response = $userServiceClient->listUsers($request); 
 $count = 0; 
 foreach ($response->iterateAllElements() as $element) { 
 print_r($element); 
 $count++; 
 } 
 print "The following count of elements were returned: "; 
 print $count . "\n"; 
 } catch (ApiException $e) { 
 print $e->getMessage(); 
 } 
 } 
 $config = Config::generateConfig(); 
 listUsers($config);  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 ListUsersRequest 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UserServiceClient 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 get_parent 
 ( 
 account_id 
 ): 
 return 
 f 
 "accounts/ 
 { 
 account_id 
 } 
 " 
 def 
  
 list_users 
 (): 
  
 """Lists all the users for a given Merchant Center account.""" 
 # Get OAuth credentials 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a UserServiceClient 
 client 
 = 
 UserServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create parent string 
 parent 
 = 
 get_parent 
 ( 
 _ACCOUNT 
 ) 
 # Create the request 
 request 
 = 
 ListUsersRequest 
 ( 
 parent 
 = 
 parent 
 ) 
 try 
 : 
 print 
 ( 
 "Sending list users request:" 
 ) 
 response 
 = 
 client 
 . 
 list_users 
 ( 
 request 
 = 
 request 
 ) 
 count 
 = 
 0 
 for 
 element 
 in 
 response 
 : 
 print 
 ( 
 element 
 ) 
 count 
 += 
 1 
 print 
 ( 
 "The following count of elements were returned: " 
 ) 
 print 
 ( 
 count 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 list_users 
 () 
  
 

cURL

  curl -L -X GET \ 
 'https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users' \ 
 -H 'Authorization: Bearer <API_TOKEN>' 
 

Get details for a specific user

To fetch detailed information about a specific user associated with your Merchant Center account, including their current access rights and status (for example, VERIFIED or PENDING ), you can use their Google email address.

This corresponds to the users.get method.

  GET https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
 
 

A successful request returns a 200 OK HTTP status code and a response body with the User resource:

  { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
" 
 , 
  
 "state" 
 : 
  
 "VERIFIED" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "ADMIN" 
  
 ] 
 } 
 

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.GetUserRequest 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.User 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserName 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to get a single user for a given Merchant Center account. */ 
 public 
  
 class 
 GetUserSample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 getUser 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 email 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 UserServiceSettings 
  
 userServiceSettings 
  
 = 
  
 UserServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates user name to identify user. 
  
 String 
  
 name 
  
 = 
  
 UserName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 setEmail 
 ( 
 email 
 ) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 UserServiceClient 
  
 userServiceClient 
  
 = 
  
 UserServiceClient 
 . 
 create 
 ( 
 userServiceSettings 
 )) 
  
 { 
  
 // The name has the format: accounts/{account}/users/{email} 
  
 GetUserRequest 
  
 request 
  
 = 
  
 GetUserRequest 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 name 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending Get user request:" 
 ); 
  
 User 
  
 response 
  
 = 
  
 userServiceClient 
 . 
 getUser 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Retrieved User below" 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 response 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 // The email address of this user. If you want to get the user information 
  
 // Of the user making the Content API request, you can also use "me" instead 
  
 // Of an email address. 
  
 String 
  
 email 
  
 = 
  
 "testUser@gmail.com" 
 ; 
  
 getUser 
 ( 
 config 
 , 
  
 email 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Accounts\V1\GetUserRequest; 
 use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient; 
 /** 
 * Retrieves a user. 
 * 
 * @param array $config The configuration data. 
 * @param string $email The email address of the user. 
 * @return void 
 */ 
 function getUser($config, $email): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $userServiceClient = new UserServiceClient($options); 
 // Creates user name to identify user. 
 $name = 'accounts/' . $config['accountId'] . "/users/" . $email; 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new GetUserRequest(['name' => $name]); 
 print "Sending Get user request:\n"; 
 $response = $userServiceClient->getUser($request); 
 print "Retrieved User below\n"; 
 print_r($response); 
 } catch (ApiException $e) { 
 print $e->getMessage(); 
 } 
 } 
 $config = Config::generateConfig(); 
 $email = "testUser@gmail.com"; 
 getUser($config, $email);  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 GetUserRequest 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UserServiceClient 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 get_user 
 ( 
 user_email 
 ): 
  
 """Gets a single user for a given Merchant Center account.""" 
 # Get OAuth credentials 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a UserServiceClient 
 client 
 = 
 UserServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create user name string 
 name 
 = 
 "accounts/" 
 + 
 _ACCOUNT 
 + 
 "/users/" 
 + 
 user_email 
 # Create the request 
 request 
 = 
 GetUserRequest 
 ( 
 name 
 = 
 name 
 ) 
 try 
 : 
 print 
 ( 
 "Sending Get user request:" 
 ) 
 response 
 = 
 client 
 . 
 get_user 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Retrieved User below" 
 ) 
 print 
 ( 
 response 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 # Modify this email to get the user details 
 email 
 = 
 "USER_MAIL_ACCOUNT" 
 get_user 
 ( 
 email 
 ) 
  
 

cURL

  curl -L -X GET \ 
 'https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
' \ 
 -H 'Authorization: Bearer <API_TOKEN>' 
 

You can grant a user access to your Merchant Center account by providing their Google email address and specifying their intended access rights. This action sends an invitation to the user. After they accept, they are able to access the account with the permissions you've defined.

This corresponds to the users.create method.

  POST https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users?userId= {USER_EMAILID} 
 
 

Request body:

  { 
  
 "accessRights" 
 : 
  
 [ 
  
 "STANDARD" 
 , 
  
 "PERFORMANCE_REPORTING" 
  
 ], 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/ {NAME} 
" 
 } 
 

Replace the following:

  • {ACCOUNT_ID} : The unique identifier of your Merchant Center account.
  • {USER_EMAILID} : The email address of the user you want to add.
  • {NAME} : The resource name of the user in the format accounts/ {ACCOUNT_ID} /user/ {EMAIL_ADDRESS} .

A successful request returns a 200 OK HTTP status code and a response body with the newly created User resource, typically in a PENDING state until the user accepts the invitation.

  { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
" 
 , 
  
 "state" 
 : 
  
 "PENDING" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "STANDARD" 
 , 
  
 "PERFORMANCE_REPORTING" 
  
 ] 
 } 
 

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.AccessRight 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.CreateUserRequest 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.User 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to create a user for a Merchant Center account. */ 
 public 
  
 class 
 CreateUserSample 
  
 { 
  
 private 
  
 static 
  
 String 
  
 getParent 
 ( 
 String 
  
 accountId 
 ) 
  
 { 
  
 return 
  
 String 
 . 
 format 
 ( 
 "accounts/%s" 
 , 
  
 accountId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 createUser 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 email 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 UserServiceSettings 
  
 userServiceSettings 
  
 = 
  
 UserServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates parent to identify where to insert the user. 
  
 String 
  
 parent 
  
 = 
  
 getParent 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 UserServiceClient 
  
 userServiceClient 
  
 = 
  
 UserServiceClient 
 . 
 create 
 ( 
 userServiceSettings 
 )) 
  
 { 
  
 CreateUserRequest 
  
 request 
  
 = 
  
 CreateUserRequest 
 . 
 newBuilder 
 () 
  
 . 
 setParent 
 ( 
 parent 
 ) 
  
 // This field is the email address of the user. 
  
 . 
 setUserId 
 ( 
 email 
 ) 
  
 . 
 setUser 
 ( 
  
 User 
 . 
 newBuilder 
 () 
  
 . 
 addAccessRights 
 ( 
 AccessRight 
 . 
 ADMIN 
 ) 
  
 . 
 addAccessRights 
 ( 
 AccessRight 
 . 
 PERFORMANCE_REPORTING 
 ) 
  
 . 
 build 
 ()) 
  
 . 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending Create User request" 
 ); 
  
 User 
  
 response 
  
 = 
  
 userServiceClient 
 . 
 createUser 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Inserted User Name below" 
 ); 
  
 // The last part of the user name will be the email address of the user. 
  
 // Format: `accounts/{account}/user/{user}` 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 response 
 . 
 getName 
 ()); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 // The email address of this user. 
  
 String 
  
 email 
  
 = 
  
 "testUser@gmail.com" 
 ; 
  
 createUser 
 ( 
 config 
 , 
  
 email 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Accounts\V1\AccessRight; 
 use Google\Shopping\Merchant\Accounts\V1\CreateUserRequest; 
 use Google\Shopping\Merchant\Accounts\V1\User; 
 use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient; 
 /** 
 * Creates a user. 
 * 
 * @param array $config The configuration data. 
 * @param string $email The email address of the user. 
 * @return void 
 */ 
 function createUser($config, $email): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $userServiceClient = new UserServiceClient($options); 
 // Creates parent to identify where to insert the user. 
 $parent = sprintf("accounts/%s", $config['accountId']); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new CreateUserRequest([ 
 'parent' => $parent, 
 'user_id' => $email, 
 'user' => (new User()) 
 ->setAccessRights([AccessRight::ADMIN,AccessRight::PERFORMANCE_REPORTING]) 
 ]); 
 print "Sending Create User request\n"; 
 $response = $userServiceClient->createUser($request); 
 print "Inserted User Name below\n"; 
 print $response->getName() . "\n"; 
 } catch (ApiException $e) { 
 print $e->getMessage(); 
 } 
 } 
 $config = Config::generateConfig(); 
 $email = "testUser@gmail.com"; 
 createUser($config, $email);  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 AccessRight 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 CreateUserRequest 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 User 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UserServiceClient 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 get_parent 
 ( 
 account_id 
 ): 
 return 
 f 
 "accounts/ 
 { 
 account_id 
 } 
 " 
 def 
  
 create_user 
 ( 
 user_email 
 ): 
  
 """Creates a user for a Merchant Center account.""" 
 # Get OAuth credentials 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a UserServiceClient 
 client 
 = 
 UserServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create parent string 
 parent 
 = 
 get_parent 
 ( 
 _ACCOUNT 
 ) 
 # Create the request 
 request 
 = 
 CreateUserRequest 
 ( 
 parent 
 = 
 parent 
 , 
 user_id 
 = 
 user_email 
 , 
 user 
 = 
 User 
 ( 
 access_rights 
 = 
 [ 
 AccessRight 
 . 
 ADMIN 
 , 
 AccessRight 
 . 
 PERFORMANCE_REPORTING 
 ] 
 ), 
 ) 
 try 
 : 
 print 
 ( 
 "Sending Create User request" 
 ) 
 response 
 = 
 client 
 . 
 create_user 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Inserted User Name below" 
 ) 
 print 
 ( 
 response 
 . 
 name 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 # Modify this email to create a new user 
 email 
 = 
 "USER_MAIL_ACCOUNT" 
 create_user 
 ( 
 email 
 ) 
  
 

cURL

  curl -L -X POST \ 
 'https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users?userId=newuser@example.com' \ 
 -H 'Authorization: Bearer <API_TOKEN>' \ 
 -H 'Content-Type: application/json' \ 
 --data-raw '{ 
 "accessRights": [ 
 "STANDARD" 
 ] 
 }' 
 

Update a user's access rights

You can modify the access level of an existing user in your Merchant Center account. For example, you can elevate a user from STANDARD to ADMIN access, or add PERFORMANCE_REPORTING rights. The changes take effect immediately for verified users.

This corresponds to the users.update method. You need to specify the updateMask query parameter to indicate which fields are being updated, in this case, accessRights .

  PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
?updateMask=accessRights 
 

Request body:

  { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "ADMIN" 
 , 
  
 "PERFORMANCE_REPORTING" 
  
 ] 
 } 
 

A successful request returns a 200 OK HTTP status code and a response body with the updated User resource.

  { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
" 
 , 
  
 "state" 
 : 
  
 "VERIFIED" 
 , 
  
 "accessRights" 
 : 
  
 [ 
  
 "ADMIN" 
 , 
  
 "PERFORMANCE_REPORTING" 
  
 ] 
 } 
 

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.protobuf.FieldMask 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.AccessRight 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UpdateUserRequest 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.User 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserName 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to update a user to make it an admin of the MC account. */ 
 public 
  
 class 
 UpdateUserSample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 updateUser 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 email 
 , 
  
 AccessRight 
  
 accessRight 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 UserServiceSettings 
  
 userServiceSettings 
  
 = 
  
 UserServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates user name to identify user. 
  
 String 
  
 name 
  
 = 
  
 UserName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 setEmail 
 ( 
 email 
 ) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 // Create a user with the updated fields. 
  
 User 
  
 user 
  
 = 
  
 User 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 name 
 ). 
 addAccessRights 
 ( 
 accessRight 
 ). 
 build 
 (); 
  
 FieldMask 
  
 fieldMask 
  
 = 
  
 FieldMask 
 . 
 newBuilder 
 (). 
 addPaths 
 ( 
 "access_rights" 
 ). 
 build 
 (); 
  
 try 
  
 ( 
 UserServiceClient 
  
 userServiceClient 
  
 = 
  
 UserServiceClient 
 . 
 create 
 ( 
 userServiceSettings 
 )) 
  
 { 
  
 UpdateUserRequest 
  
 request 
  
 = 
  
 UpdateUserRequest 
 . 
 newBuilder 
 (). 
 setUser 
 ( 
 user 
 ). 
 setUpdateMask 
 ( 
 fieldMask 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending Update User request" 
 ); 
  
 User 
  
 response 
  
 = 
  
 userServiceClient 
 . 
 updateUser 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Updated User Name below" 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 response 
 . 
 getName 
 ()); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 String 
  
 email 
  
 = 
  
 "testUser@gmail.com" 
 ; 
  
 // Give the user admin rights. Note that all other rights, like 
  
 // PERFORMANCE_REPORTING, would be overwritten in this example 
  
 // if the user had those access rights before the update. 
  
 AccessRight 
  
 accessRight 
  
 = 
  
 AccessRight 
 . 
 ADMIN 
 ; 
  
 updateUser 
 ( 
 config 
 , 
  
 email 
 , 
  
 accessRight 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Protobuf\FieldMask; 
 use Google\Shopping\Merchant\Accounts\V1\AccessRight; 
 use Google\Shopping\Merchant\Accounts\V1\UpdateUserRequest; 
 use Google\Shopping\Merchant\Accounts\V1\User; 
 use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient; 
 /** 
 * Updates a user. 
 * 
 * @param array $config The configuration data. 
 * @param string $email The email address of the user. 
 * @param int $accessRight The access right to grant the user. 
 * @return void 
 */ 
 function updateUser($config, $email, $accessRights): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $userServiceClient = new UserServiceClient($options); 
 // Creates user name to identify user. 
 $name = 'accounts/' . $config['accountId'] . "/users/" . $email; 
 $user = (new User()) 
 ->setName($name) 
 ->setAccessRights($accessRights); 
 $fieldMask = (new FieldMask())->setPaths(['access_rights']); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new UpdateUserRequest([ 
 'user' => $user, 
 'update_mask' => $fieldMask, 
 ]); 
 print "Sending Update User request\n"; 
 $response = $userServiceClient->updateUser($request); 
 print "Updated User Name below\n"; 
 print $response->getName() . "\n"; 
 } catch (ApiException $e) { 
 print $e->getMessage(); 
 } 
 } 
 $config = Config::generateConfig(); 
 $email = "testUser@gmail.com"; 
 $accessRights = [AccessRight::ADMIN]; 
 updateUser($config, $email, $accessRights);  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.protobuf 
  
 import 
 field_mask_pb2 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 AccessRight 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UpdateUserRequest 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 User 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UserServiceClient 
 FieldMask 
 = 
 field_mask_pb2 
 . 
 FieldMask 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 update_user 
 ( 
 user_email 
 , 
 user_access_right 
 ): 
  
 """Updates a user to make it an admin of the MC account.""" 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 client 
 = 
 UserServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create user name string 
 name 
 = 
 "accounts/" 
 + 
 _ACCOUNT 
 + 
 "/users/" 
 + 
 user_email 
 user 
 = 
 User 
 ( 
 name 
 = 
 name 
 , 
 access_rights 
 = 
 [ 
 user_access_right 
 ]) 
 field_mask 
 = 
 FieldMask 
 ( 
 paths 
 = 
 [ 
 "access_rights" 
 ]) 
 try 
 : 
 request 
 = 
 UpdateUserRequest 
 ( 
 user 
 = 
 user 
 , 
 update_mask 
 = 
 field_mask 
 ) 
 print 
 ( 
 "Sending Update User request" 
 ) 
 response 
 = 
 client 
 . 
 update_user 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Updated User Name below" 
 ) 
 print 
 ( 
 response 
 . 
 name 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 # Modify this email to update the right user 
 email 
 = 
 "USER_MAIL_ACCOUNT" 
 access_right 
 = 
 AccessRight 
 . 
 ADMIN 
 update_user 
 ( 
 email 
 , 
 access_right 
 ) 
  
 

cURL

  curl -L -X PATCH \ 
 'https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
?updateMask=accessRights' \ 
 -H 'Authorization: Bearer <API_TOKEN>' \ 
 -H 'Content-Type: application/json' \ 
 --data-raw '{ 
 "name": "accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
", 
 "accessRights": [ 
 "ADMIN", 
 "PERFORMANCE_REPORTING" 
 ] 
 }' 
 

You can revoke a user's access to your Merchant Center account. This action permanently removes their ability to sign in and perform any actions associated with your account.

This corresponds to the users.delete method.

  DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
 
 

A successful request returns a 200 OK HTTP status code with an empty response {} body, confirming the user has been removed.

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.DeleteUserRequest 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserName 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UserServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to delete a user for a given Merchant Center account. */ 
 public 
  
 class 
 DeleteUserSample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 deleteUser 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 email 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 UserServiceSettings 
  
 userServiceSettings 
  
 = 
  
 UserServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates user name to identify the user. 
  
 String 
  
 name 
  
 = 
  
 UserName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 setEmail 
 ( 
 email 
 ) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 UserServiceClient 
  
 userServiceClient 
  
 = 
  
 UserServiceClient 
 . 
 create 
 ( 
 userServiceSettings 
 )) 
  
 { 
  
 DeleteUserRequest 
  
 request 
  
 = 
  
 DeleteUserRequest 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 name 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending Delete User request" 
 ); 
  
 userServiceClient 
 . 
 deleteUser 
 ( 
 request 
 ); 
  
 // no response returned on success 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Delete successful." 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 // The email address of this user. If you want to delete the user information 
  
 // Of the user making the Content API request, you can also use "me" instead 
  
 // Of an email address. 
  
 String 
  
 email 
  
 = 
  
 "testUser@gmail.com" 
 ; 
  
 deleteUser 
 ( 
 config 
 , 
  
 email 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Accounts\V1\DeleteUserRequest; 
 use Google\Shopping\Merchant\Accounts\V1\Client\UserServiceClient; 
 /** 
 * Deletes a user. 
 * 
 * @param array $config The configuration data. 
 * @param string $email The email address of the user. 
 * @return void 
 */ 
 function deleteUser($config, $email): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $userServiceClient = new UserServiceClient($options); 
 // Creates user name to identify the user. 
 $name = 'accounts/' . $config['accountId'] . "/users/" . $email; 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new DeleteUserRequest(['name' => $name]); 
 print "Sending Delete User request\n"; 
 $userServiceClient->deleteUser($request); 
 print "Delete successful.\n"; 
 } catch (ApiException $e) { 
 print $e->getMessage(); 
 } 
 } 
 $config = Config::generateConfig(); 
 $email = "testUser@gmail.com"; 
 deleteUser($config, $email);  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 DeleteUserRequest 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UserServiceClient 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 delete_user 
 ( 
 user_email 
 ): 
  
 """Deletes a user for a given Merchant Center account.""" 
 # Get OAuth credentials 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a UserServiceClient 
 client 
 = 
 UserServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create user name string 
 name 
 = 
 "accounts/" 
 + 
 _ACCOUNT 
 + 
 "/users/" 
 + 
 user_email 
 # Create the request 
 request 
 = 
 DeleteUserRequest 
 ( 
 name 
 = 
 name 
 ) 
 try 
 : 
 print 
 ( 
 "Sending Delete User request" 
 ) 
 client 
 . 
 delete_user 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Delete successful." 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 # Modify this email to delete the right user 
 email 
 = 
 "USER_MAIL_ACCOUNT" 
 delete_user 
 ( 
 email 
 ) 
  
 

cURL

  curl -L -X DELETE \ 
 'https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID} 
/users/ {USER_EMAILID} 
' \ 
 -H 'Authorization: Bearer <API_TOKEN>' 
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: