To access Google Apps, an end user must have a Google-hosted account. This document describes the Google Apps Provisioning API, which enables Google partners to create, retrieve, update and delete user accounts. Partners can also use the API to create email accounts, user aliases and mailing lists.
This document explains the formats for all of the different types of API requests as well as the format of the API's XML responses to those requests.
To set up Google Apps, you will need to create a Google account that will serve as an admin account for your domain. You can use an existing Google account. However, since the owner of the account will have the ability to create, update and delete user accounts for your domain, we recommend that you consider creating a new Google account for your domain rather than using someone's personal Google account.
The following steps explain how you would set up Google Apps.
Go to the home page for Google Apps and follow the instructions to sign up for Google Apps Premier Edition (for your enterprise) or Google Apps Education Edition (for your school).
Enter your domain name or indicate that you would like to purchase a new domain. If you purchase a new domain, you will need to complete the registration forms for the new domain before proceeding to the next step.
Complete the form to provide information about your organization and yourself to Google.

On the following page, complete the form indicating the number of user accounts you would like to purchase and then accept the terms and conditions.

Complete the signup process using Google Checkout.

Complete the form to set up your admin account.

Follow the instructions to verify that you own your domain.
Use the email address and password for your admin account to request an authentication token for your domain. The authentication token will be submitted in each API request that you send to Google, and Google will use the authentication token to authorize the execution of those API requests.
To use the API, you will send HTTP POST requests to Google that instruct Google to perform a create, retrieve, update or delete operation on a resource in your domain. Resources include user accounts, email aliases and mailing lists. Note: The Google Apps online control panel refers to aliases as nicknames and to mailing lists as email lists.
This section explains the different types of operations that the API supports. The Submitting API Requests section identifies the URL that corresponds to each API operation.
Create operations enable partners to add new user accounts, email aliases and mailing lists. The Submitting API Requests section identifies the URL that corresponds to each API operation.
Retrieve operations allow Google partners to request and obtain information about user accounts, email aliases and mailing lists.
The XML for a retrieve request identifies a queryKey, which indicates the type of resource that is being retrieved. A retrieve request also specifies a queryData value, which identifies the particular resource being retrieved. Google will locate the resource identified in your request and return the corresponding information in the API response.
Update operations allow Google partners to modify information about user accounts and mailing lists. Note: The API does not support updates to email aliases. The API supports the following types of updates:
Update requests also use the <queryKey> and <queryData> XML elements to identify the resource being updated. When you submit an update request, Google will locate the appropriate resource and update it to match the information in the <UpdateSection> node of the XML request.
Delete operations allow Google partners to delete user accounts, email aliases and mailing lists.
Like retrieve and update requests, delete requests use the <queryKey> and <queryData> XML elements to identify the resource being deleted. Google will locate the resource specified in your request, delete it, and return a success or failure message in the API response.
After you delete an account, you must wait five days before reassigning the username for the deleted account to another account.
Google will verify that all Create and Update requests contain valid XML, include all required data fields and meet authentication requirements.
All of your API requests must be sent over HTTPS. In addition, all data sent to the API will be delivered using HTTPS POST to ensure the security of that data.
Each API request that you send needs to contain an authentication token, which Google will use to authorize access to the operation specified in the API request. Authentication tokens are only available to users who have administrative rights in your domain, and those tokens only authorize operations within your domain.
The ClientLogin Interface provides additional information about programmatically logging users into their accounts.
To obtain an authentication token, submit an HTTP POST request to the following URL:
The following guidelines apply to the request:
The POST body needs to include a string in the following format:
You will need to make the following changes to this string:
Replace the string <email_address> with the email address for your admin account.
Replace the string <password> with the password for that account.
The email address and password in the POST body must be URL-encoded. For example, the URL-encoded form of the email address apps.test.account@example.com is apps%2Etest%2Eaccount%40example%2Ecom.
The POST request must specify the value application/x-www-form-urlencoded for the Content-Type header.
Google will return a response containing your authentication token in response to your POST request. The authentication token will be the SID value on that page. You need to extract the token from the page and then submit that token in API requests.
Note: Authentication tokens expire after 24 hours. As such, you will need to submit a request to the above URL at least once every 24 hours. We recommend that you keep the token in memory rather than writing it to a file.
The following Perl script demonstrates how to make an HTTP POST request for an authentication token.
#! /usr/bin/perl -w use strict; use LWP::UserAgent; # Create an LWP object to make the HTTP POST request my $lwp_object = LWP::UserAgent->new; # Define the URL to submit the request to my $url = 'https://www.google.com/accounts/ClientLogin'; # Submit the request with values for the accountType, # Email and Passwd variables. my $response = $lwp_object->post( $url, [ 'accountType' => 'HOSTED', 'Email' => 'admin_email@example.com', 'Passwd' => 'admin_password' ] ); die "$url error: ", $response->status_line unless $response->is_success; # Extract the authentication token from the response my $auth_token; foreach my $line (split/\n/, $response->content) { if ($line =~ m/^SID=(.+)$/) { $auth_token = $1; last; } } print "authentication token is $auth_token\n";
Note that to use this code, you need to replace the Email and Passwd values with the email address and password for your admin account.
To execute an operation using the API, you need to POST an appropriately formatted XML document to the URL that corresponds to that operation. The following table lists the different operations available in version 1.0 of the API. The table also identifies the URL to which you would submit an API request for each operation.
| Operation | URL |
|---|---|
| Create Account with Email | https://www.google.com/a/services/v1.0/Create/Account/Email |
| Create Alias | https://www.google.com/a/services/v1.0/Create/Alias |
| Create Mailing List | https://www.google.com/a/services/v1.0/Create/MailingList |
| Update Account | https://www.google.com/a/services/v1.0/Update/Account |
| Update Account Status (locked/unlocked) | https://www.google.com/a/services/v1.0/Update/Account/Status |
| Update Mailing List | https://www.google.com/a/services/v1.0/Update/MailingList |
| Retrieve Account | https://www.google.com/a/services/v1.0/Retrieve/Account |
| Retrieve Alias | https://www.google.com/a/services/v1.0/Retrieve/Alias |
| Retrieve Mailing List | https://www.google.com/a/services/v1.0/Retrieve/MailingList |
| Delete Account | https://www.google.com/a/services/v1.0/Delete/Account |
| Delete Alias | https://www.google.com/a/services/v1.0/Delete/Alias |
| Delete Mailing List | https://www.google.com/a/services/v1.0/Delete/MailingList |
The following sections contain sample API requests to Create, Retrieve, Update and Delete user accounts, email aliases and mailing lists:
These sections provide a sample API request for each operation that you can perform using the API. These sections also discuss the XML tags used in each API request. Definitions for these XML tags are provided in Appendix A - XML Tag Definitions for API Requests.
As described earlier, your users must have a user account to access Google Apps for your domain. The following subsections show the proper API request syntax for creating, updating, retrieving and deleting Google user accounts.
*Note: Each command marked with an asterisk (*) updates an account in a different way.
This example shows a request to create a user account.
In this request, the value of the <type> tag is Account. The <CreateSection> tag has four required subtags:
The <CreateSection> tag in the example also contains the <quota> tag. Please note that this tag, which is used in a request to create an account with email, is required for domains that have the ability to customize the disk space quota allocated to their email accounts.
This example shows a request to update a user account.
The URL to use for this request is:
In this request, the value of the <type> tag is Account. In addition, the queryKey value (userName) indicates that Google Apps should look up a user account, and the queryData value identifies the account to be located (john-doe).
The <UpdateSection> tag in this request has three optional subtags. A request may include any combination of the three subtags and only the corresponding values will be updated.
This example shows a request to lock, or disable, a user's email account.
The URL to use for this request is:
In this request, the value of the <type> tag is Account. In addition, the queryKey value (userName) indicates that Google Apps should look up a user account, and the queryData value identifies the account to be located (john-doe).
The <UpdateSection> tag in this request has one required subtag:
<accountStatus> - Valid values for this tag are locked, which disables the specified email account, and unlocked, which enables the specified email account. An end user cannot log in to a disabled account, and email sent to the account will not be delivered.
This example shows a request to retrieve information about a user account.
The URL to use for this request is:
API requests to retrieve user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To retrieve information about a user account, set the value of the <type> tag to Account and the value of the <queryKey> tag to userName. Also set the value of the <queryData> tag to the name of the user account to be retrieved.
This example shows a request to delete a user account.
The URL to use for this request is:
API requests to delete user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To delete a user account, set the value of the <type> tag to Account and the value of the <queryKey> tag to userName. Also set the value of the <queryData> tag to the name of the user account to be deleted.
Email aliases enable a single email account to receive email sent to more than one email address. However, an alias should not be considered an alternate userName for an account. For example, a user cannot log in to an account using an alias name.
The following subsections demonstrate the proper syntax for creating, retrieving and deleting aliases through the API. (Aliases cannot be updated.)
This example shows a request to create an email alias.
In this request, the value of the <type> tag is Alias. The <CreateSection> tag has two required subtags:
<userName> - This value identifies the user to whom the alias is assigned.
<aliasName> - This value identifies the name of the alias to be created.
This example shows a request to retrieve information about an email alias.
The URL to use for this request is:
API requests to retrieve user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To retrieve information about an email alias, set the value of the <type> tag to Alias and the value of the <queryKey> tag to aliasName. Also set the value of the <queryData> tag to the name of the email alias to be retrieved.
This example shows a request to delete an email alias.
The URL to use for this request is:
API requests to delete user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To delete an email alias, set the value of the <type> tag to Alias and the value of the <queryKey> tag to aliasName. Also set the value of the <queryData> tag to the name of the email alias to be deleted.
Mailing lists enable many different users to receive email sent to a single email address. The following subsections show the proper API request syntax for creating, updating, retrieving and deleting mailing lists.
Note: Mailing lists are always empty when you create them. After creating a mailing list, you will need to update the mailing list to add users to it. A user must already have a user account before she can be added to a mailing list.
This example shows a request to create a mailing list.
In this request, the value of the <type> tag is MailingList. In addition, the <CreateSection> tag has one required subtag (<mailingListName>), which identifies the list to be created.
This example shows a request to update a mailing list.
The URL to use for this request is:
In this request, the value of the <type> tag is MailingList. In addition, the queryKey value (mailingListName) indicates that Google Apps should look up a mailing list, and the queryData value identifies the mailing list to be located (sales-europe).
The <UpdateSection> tag contains two required subtags:
<userName> - This tag identifies the user who is being added to or removed from the mailing list.
<listOperation> - This tag indicates whether the user should be added to the list or removed from the list. Valid values for this tag are add and remove.
This example shows a request to retrieve information about a mailing list.
The URL to use for this request is:
API requests to retrieve user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To retrieve information about a mailing list, set the value of the <type> tag to MailingList and the value of the <queryKey> tag to mailingListName. Also set the value of the <queryData> tag to the name of the mailing list to be retrieved.
This example shows a request to delete a mailing list.
The URL to use for this request is:
API requests to delete user accounts, email aliases and mailing lists all use the same XML structure. The only differences between the requests are the values of the <type>, <queryKey> and <queryData> tags.
To delete a mailing list, set the value of the <type> tag to MailingList and the value of the <queryKey> tag to mailingListName. Also set the value of the <queryData> tag to the name of the mailing list to be deleted.
The API will log each operation in which a user account is created, updated or deleted for your domain. Logs are available on a per-domain basis.
Note: Usernames and passwords for your accounts are not recorded in logs.
The API returns an XML response to all API requests that are sent to a valid API URL. The XML response indicates whether Google processed the API request successfully. (Google does not return XML responses to requests sent to invalid API URLs.)
If a response is processed successfully, the <status> tag in the XML response will contain the text Success(2000).
If a request is not processed successfully, the <status> tag in the XML response will contain the text Failure(2001) and the <reason> tag will contain an error code that explains the cause of the failure.
The following list contains the XML tags that may appear in an API response. These tags are defined in Appendix B - XML Tag Definitions for API Responses. In addition, the Sample API Responses section of this document contains sample XML responses for both successful and unsuccessful API requests.
* Note: The URLs that correspond to each API operation are listed in the Submitting API Requests section of this document. If you send an API request to a URL that is not in that list, Google will return an HTTP 301 response code, indicating that the requested URL has been permanently redirected. If you receive an HTTP 301 response code from the API, please verify that you are sending your POST requests to a valid API URL.
The following examples demonstrate the syntax used for API XML responses.
The syntax of an API response is identical for Create, Update and Delete requests. This syntax is shown below in example 1. Responses to Retrieve requests use some additional tags. Those tags vary depending on whether the API request was for user account or mailing list information. The syntax for returning user account information is shown in example 2, and the syntax for returning mailing list information is shown in example 3.
Example 1: Successful Response to Create, Update or Delete Request
Example 2: Successful Response to Retrieve Account Information
Example 3: Successful Response to Retrieve Mailing List Information
The following appendixes contain definitions of the XML tags used in API XML requests and responses.
Note: The tags in both appendixes are presented in alphabetical order. However, in API requests, XML tags must appear in a specific sequence. The sections on sample API requests for user accounts, email aliases and mailing lists show the sequence in which tags must appear in your API requests.
Certain symbols may be displayed next to some subtags in the definitions below. These symbols, and their meanings, are:
| accountStatus | |
| Definition | The <accountStatus> tag indicates whether a user account should be enabled or disabled. This tag is only used in API requests to update the status of an account. Valid values for this tag are locked, which means a user account should be disabled, and unlocked, which indicates that a user account should be enabled. |
| Action | Update (only used to update account status) |
| Example | <hs:accountStatus>locked</hs:accountStatus> |
| Subtag of | UpdateSection |
| Content Format | Text |
| aliasName | |
| Definition | The <aliasName> tag identifies an email alias that should be created. |
| Action | Create |
| Example | <hs:aliasName>webmaster</hs:aliasName> |
| Subtag of | CreateSection |
| Content Format | Text |
| CreateSection | |
| Definition | The <CreateSection> tag encapsulates information about a new user account, email alias or mailing list. |
| Action | Create |
| Example | <hs:CreateSection> |
| Subtags | For creating user accounts: firstName, lastName, password, userName, quota? For creating email aliases: userName, aliasName For creating mailing lists: mailingListName |
| Subtag of | rest |
| Content Format | Empty |
| domain | |
| Definition | The <domain> tag identifies the Google partner domain for a user account, email alias or mailing list. |
| Action | Create, Retrieve, Update, Delete |
| Example | <hs:domain>example.com</hs:domain> |
| Subtag of | rest |
| Content Format | Text |
| firstName | |
| Definition | The <firstName> tag identifies the user's first name. The value of the <firstName> tag must be 40 characters or shorter. |
| Action | Create, Update |
| Example | <hs:firstName>John</hs:firstName> |
| Subtag of | CreateSection, UpdateSection |
| Content Format | Text |
| lastName | |
| Definition | The <lastName> tag identifies the user's last name. The value of the <lastName> tag must be 40 characters or shorter. |
| Action | Create, Update |
| Example | <hs:lastName>Doe</hs:lastName> |
| Subtag of | CreateSection, UpdateSection |
| Content Format | Text |
| listOperation | |
| Definition | The <listOperation> tag indicates whether a name should be added to a mailing list or removed from a mailing list. Valid values for this tag are: add and remove. |
| Action | Update (mailing list only) |
| Example | <hs:listOperation>add</hs:listOperation> |
| Subtag of | UpdateSection |
| Content Format | Text |
| mailingListName | |
| Definition | The <mailingListName> tag identifies the name of a mailing list that should be created. |
| Action | Create |
| Example | <hs:mailingListName>sales-us</hs:mailingListName> |
| Subtag of | CreateSection |
| Content Format | Text |
| password | |
| Definition | The <password> tag identifies the user's password. Passwords must be between six characters and 100 characters in length. |
| Action | Create, Update |
| Example | <hs:password>123abc</hs:password> |
| Subtag of | CreateSection, UpdateSection |
| Content Format | Text |
| queryData | |
| Definition | The <queryData> value is combined with the queryKey value to uniquely identify a user account within a particular domain. The queryKey identifies a lookup field (e.g. userName) while the queryData tag identifies the lookup value. |
| Action | Retrieve, Delete |
| Example | <hs:queryData>john_doe</hs:queryData> |
| Subtag of | rest |
| Content Format | Text |
| queryKey | |
| Definition | The <queryKey> value is combined with the queryData value to uniquely identify a user account, email alias or mailing list within a particular domain. The queryKey identifies a lookup field (e.g. userName) while the queryData tag identifies the lookup value. Note: The only valid values for this tag are:
|
| Action | Retrieve, Delete |
| Example | <hs:queryKey>userName</hs:queryKey> |
| Subtag of | rest |
| Content Format | Text |
| quota | |
| Definition | The <quota> tag specifies the amount of storage space, in megabytes, that should be allocated to an email account. The storage quota for an account may only be set at the time the account is created. The default value for this tag is 2048. Additional valid values may be specified in your agreement. Note: Domains that have additional valid quotas specified in their contracts must specify a value for the <quota> element in requests to create email accounts. Domains that do not have additional valid quota values specified in their contracts may omit the <quota> element from requests to create email accounts. If requests from these domains do specify a <quota> value, that value will be ignored. |
| Action | Create Account with Email |
| Example | <hs:quota>2048</hs:quota> |
| Subtag of | CreateSection? |
| Content Format | Integer |
| rest | |
| Definition | The <rest> tag encapsulates the information in an API request or response. |
| Action | Create, Retrieve, Delete, Update, Response |
| Example | <hs:rest xmlns:hs="google:accounts:rest:protocol" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| Subtags | type, token, domain, queryKey, queryData, CreateSection, UpdateSection |
| Content Format | Text |
| token | |
| Definition | The <token> tag contains a value used to authorize access to create, retrieve, update or delete an account, email alias or mailing list on a particular domain. For more information about this value, please see the Authentication and Obtaining an Authentication Token sections of this document. |
| Action | Create, Retrieve, Delete, Update |
| Example | <hs:token>DQAAAGAAAADa7eYOUNcbs9zZxMnLvHdEy</hs:token> |
| Subtag of | rest |
| Content Format | Text |
| type | |
| Definition | The <type> tag identifies the type of entity that is being created, retrieved, updated or deleted. Valid values for this tag are:
|
| Action | Create, Retrieve, Delete, Update |
| Example | <hs:type>Account</hs:type> |
| Subtag of | rest |
| Content Format | Text |
| UpdateSection | |
| Definition | The <UpdateSection> tag encapsulates information about a user account or mailing list that is being updated. |
| Action | Update |
| Example | <hs:UpdateSection> |
| Subtags | The following tags are used to update user information for a user account: The following tags are used to enable or disable an email account: |
| Subtag of | rest |
| Content Format | Empty |
| userName | |
| Definition | The <userName> tag identifies the username assigned to a user account. The <userName> value has a maximum length of 30 characters. Valid characters for usernames are: a-zA-Z0-9.-. Note that the only nonalphanumeric characters you may use are periods (.) and hyphens (-). In addition, usernames may not contain consecutive periods and may not begin or end with a period. Note: In requests to change the username for an account, the <userName> tag identifies the new username that should be assigned to the account, and the <queryData> tag identifies the username that is being replaced. |
| Action | Create, Update |
| Example | <hs:userName>john-doe</hs:userName> |
| Subtag of | CreateSection |
| Content Format | Text |
| accountStatus | |
| Definition | The <accountStatus> tag indicates whether the requested account is locked or unlocked. |
| Action | Response |
| Example | <hs:accountStatus>locked</hs:accountStatus> |
| Subtag of | RetrievalSection |
| Content Format | Text |
| alias | |
| Definition | The <alias> tag identifies an alias that is assigned to a user. |
| Action | Response |
| Example | <hs:alias>johnnyd@example.com</hs:alias> |
| Subtag of | aliases |
| Content Format | Text |
| aliases | |
| Definition | The <aliases> tag encapsulates a list of aliases assigned to a user. |
| Action | Response |
| Example | <hs:aliases> |
| Subtags | alias* |
| Subtag of | RetrievalSection |
| Content Format | Container |
| emailAddress | |
| Definition | The <emailAddress> tag identifies an email account that is in a mailing list. |
| Action | Response |
| Example | <hs:emailAddress>john-doe@example.com</hs:emailAddress> |
| Subtag of | emailAddresses |
| Content Format | Text |
| emailAddresses | |
| Definition | The <emailAddresses> tag encapsulates a list of email addresses that are in a mailing list. |
| Action | Response |
| Example | <hs:emailAddresses> |
| Subtags | emailAddress* |
| Subtag of | RetrievalSection |
| Content Format | Container |
| emailList | |
| Definition | The <emailList> tag identifies a mailing list to which a user is subscribed. |
| Action | Response |
| Example | <hs:emailList>sales-europe@example.com</hs:emailList> |
| Subtag of | emailLists |
| Content Format | Text |
| emailLists | |
| Definition | The <emailLists> tag encapsulates a list of mailing lists to which a user is subscribed. |
| Action | Response |
| Example | <hs:emailLists> |
| Subtags | emailList* |
| Subtag of | RetrievalSection |
| Content Format | Container |
| extendedMessage | |
| Definition | The <extendedMessage> tag contains additional details explaining why an API request failed to execute. The <extendedMessage> tag may be empty even if an API request failed to execute. For this reason, your application should not rely on this tag's value. |
| Action | Response |
| Example | <hs:extendedMessage>Supplied user is not an admin, cannot use API.</hs:extendedMessage> |
| Subtag of | rest |
| Content Format | Text |
| firstName | |
| Definition | The <firstName> tag identifies the user's first name. |
| Action | Response |
| Example | <hs:firstName>John</hs:firstName> |
| Subtag of | RetrievalSection |
| Content Format | Text |
| lastName | |
| Definition | The <lastName> tag identifies the user's last name. |
| Action | Response |
| Example | <hs:lastName>Doe</hs:lastName> |
| Subtag of | RetrievalSection |
| Content Format | Text |
| reason | |
| Definition | The <reason> tag identifies the reason that an API request failed to execute. Possible values of this tag are:
Additional details explaining the failure may be found in the extendedMessage tag. |
| Action | Response |
| Example | <hs:reason>UserAlreadyExists(1010)</hs:reason> |
| Subtag of | rest |
| Content Format | Text |
| rest | |
| Definition | The <rest> tag encapsulates the information in an API request or response. |
| Action | Create, Retrieve, Delete, Update, Response |
| Example | <hs:rest xmlns:hs="google:accounts:rest:protocol" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| Subtags | status, reason, extendedMessage, result, RetrievalSection |
| Content Format | Text |
| result | |
| Definition | The <result> tag contains the answer to a request to determine the latest version of the API. |
| Action | Response |
| Example | <hs:result>v0.9</hs:result> |
| Subtag of | rest |
| Content Format | Text |
| RetrievalSection | |
| Definition | The <RetrievalSection> tag encapsulates information returned in an API response. The <RetrievalSection> tag and its subtags are only returned if the API request is a request to retrieve data. |
| Action | RetrievalSection |
| Example | <hs:RetrievalSection> |
| Subtags | firstName?, lastName?, userName?, accountStatus?, aliases?, emailLists?, emailAddresses? |
| Subtag of | rest |
| Content Format | Empty |
| status | |
| Definition | The <status> tag indicates whether the API request was successfully executed. Possible values of this tag are Success(2000) and Failure(2001). |
| Action | Response |
| Example | <hs:status>Success(2000)</hs:status> |
| Subtag of | rest |
| Content Format | Text |
| userName | |
| Definition | The <userName> tag identifies the username assigned to a user account. |
| Action | Response |
| Example | <hs:userName>john-doe</hs:userName> |
| Subtag of | RetrievalSection |
| Content Format | Text |