### Install http-server Package Source: https://developers.google.com/workspace/admin/directory/v1/quickstart/js Install the http-server package to serve your local files. This is a prerequisite for running the quickstart application. ```bash npm install http-server ``` -------------------------------- ### End-to-End C# Example for Domain Verification and Workspace Setup Source: https://developers.google.com/workspace/admin/reseller/v1/codelab/end-to-end?hl=hi This comprehensive C# code snippet covers the entire process of setting up a Google Workspace customer, including domain verification, customer creation, admin user setup, and subscription provisioning. It requires the Reseller API, Directory API, and Site Verification API to be enabled. ```csharp var resellerService = new ResellerService(new BaseClientService.Initializer { HttpClientInitializer = credential, }); var directoryService = new DirectoryService(new BaseClientService.Initializer { HttpClientInitializer = credential, }); var verificationService = new SiteVerificationService(new BaseClientService.Initializer { HttpClientInitializer = credential, }); // Retrieve the site verification token and place it according to: // https://developers.google.com/site-verification/v1/getting_started#tokens SiteVerificationWebResourceGettokenRequest.SiteData getTokenSite = new SiteVerificationWebResourceGettokenRequest.SiteData() { Type = "INET_DOMAIN", Identifier = CUSTOMER_DOMAIN }; SiteVerificationWebResourceGettokenRequest request = new SiteVerificationWebResourceGettokenRequest() { VerificationMethod = "DNS_TXT", Site = getTokenSite }; SiteVerificationWebResourceGettokenResponse getTokenResponse = verificationService.WebResource.GetToken(request).Execute(); Console.WriteLine("Site Verification Token: {0}", getTokenResponse.Token); // Determine if customer domain already has Google Workspace try { resellerService.Customers.Get(CUSTOMER_DOMAIN).Execute(); Console.WriteLine("Customer already exists if call succeeds"); Environment.Exit(0); } catch (Google.GoogleApiException e) { if (e.Error.Code == 404) { Console.WriteLine("Domain available for Google Workspace creation"); } else throw e; } // Create customer resource Address address = new Address() { ContactName = "Marty McFly", OrganizationName = "Acme Corp", CountryCode = "US", PostalCode = "10009" }; Customer customer = new Customer() { CustomerDomain = CUSTOMER_DOMAIN, AlternateEmail = "marty.mcfly@gmail.com", PostalAddress = address }; Customer customerResponse = resellerService.Customers.Insert(customer).Execute(); Console.WriteLine("Created Customer:\n{0}", customerResponse); // Create first admin user String userEmail = "marty.mcfly@" + CUSTOMER_DOMAIN; UserName name = new UserName() { GivenName = "Marty", FamilyName = "McFly" }; User user = new User() { PrimaryEmail = userEmail, Password = "TimeCircuit88", Name = name }; User userResponse = directoryService.Users.Insert(user).Execute(); Console.WriteLine("Created User:\n{0}", userResponse); // Promote user to admin status UserMakeAdmin admin = new UserMakeAdmin() { Status = true }; directoryService.Users.MakeAdmin(admin, userEmail).Execute(); Console.WriteLine("User promoted to Admin"); // Create subscription resource Seats seats = new Seats() { NumberOfSeats = 5 }; Subscription.PlanData plan = new Subscription.PlanData() { PlanName = "ANNUAL_YEARLY_PAY" }; RenewalSettings renewalSettings = new RenewalSettings() { RenewalType = "RENEW_CURRENT_USERS_MONTHLY_PAY" }; Subscription subscription = new Subscription() { CustomerId = CUSTOMER_DOMAIN, Seats = seats, Plan = plan, SkuId = "1010020027", RenewalSettings = renewalSettings }; Subscription subscriptionResponse = resellerService.Subscriptions .Insert(subscription, CUSTOMER_DOMAIN).Execute(); Console.WriteLine("Created Subscription:\n" + subscriptionResponse); // Verify domain and designate domain owners SiteVerificationWebResourceResource.SiteData verifySite = new SiteVerificationWebResourceResource.SiteData() { Identifier = CUSTOMER_DOMAIN, Type = "INET_DOMAIN" }; string[] owners = { userEmail }; SiteVerificationWebResourceResource resource = new SiteVerificationWebResourceResource() { Site = verifySite, Owners = owners }; SiteVerificationWebResourceResource verifyResponse = verificationService.WebResource.Insert(resource, "DNS_TXT").Execute(); Console.WriteLine("Site Verification Web Resource:\n" + verifyResponse); ``` -------------------------------- ### Install Alert Center API Client Library for Python Manually Source: https://developers.google.com/workspace/admin/alertcenter/guides/libraries Manually install the Python client library by downloading, unpacking, and running the setup script. ```bash python setup.py install ``` -------------------------------- ### HTML Structure for Reseller API Quickstart Source: https://developers.google.com/workspace/admin/reseller/v1/quickstart/js This HTML file sets up the basic structure for the Google Workspace Reseller API quickstart, including buttons for authorization and sign-out, and a content area to display results. It also includes necessary JavaScript includes and initial setup. ```html Google Workspace Reseller API Quickstart

Google WOrkspace Reseller API Quickstart



    
    
    
  

```

--------------------------------

### Run the Python Quickstart Application

Source: https://developers.google.com/workspace/admin/directory/v1/quickstart/python

Execute the Python script from your working directory to run the quickstart application. This will initiate the OAuth 2.0 authorization flow if credentials are not already stored.

```bash
python3 quickstart.py

```

--------------------------------

### Example Request for a Specific Mobile Device

Source: https://developers.google.com/workspace/admin/directory/v1/guides/manage-mobile-devices.html

This is an example of a GET request to retrieve a specific mobile device's details using its resource ID and requesting the FULL projection.

```HTTP
GET https://admin.googleapis.com/admin/directory/v1/customer/my_customer/devices/
  mobile/resourceId?projection=FULL
```

--------------------------------

### Sample Request for Rules Activity

Source: https://developers.google.com/workspace/admin/reports/v1/appendix/activity/rules

Example of a GET request to retrieve activity related to DLP rules.

```APIDOC
## GET /admin/reports/v1/activity/users/all/applications/**rules**

### Description
Retrieves activity logs for DLP rules, specifically filtering for events where a label field value was changed.

### Method
GET

### Endpoint
`https://admin.googleapis.com/admin/reports/v1/activity/users/all/applications/**rules**`

### Query Parameters
* **eventName** (string) - Required - Filters activity for a specific event, e.g., `label_field_value_changed`.
* **maxResults** (integer) - Optional - The maximum number of results to return.
* **access_token** (string) - Required - Your OAuth 2.0 access token.

### Response Example (Conceptual)
```json
{
  "kind": "admin#reports#activity",
  "items": [
    {
      "id": {
        "time": "2023-10-27T10:00:00.000Z",
        "uniqueQualifier": "..."
      },
      "actor": {
        "email": "admin@example.com",
        "key": "..."
      },
      "events": [
        {
          "name": "label_field_value_changed",
          "parameters": [
            {
              "name": "label_field",
              "value": "sensitive_data"
            },
            {
              "name": "label_title",
              "value": "Confidential"
            },
            {
              "name": "old_value",
              "value": "Internal"
            },
            {
              "name": "new_value",
              "value": "Restricted"
            }
          ]
        }
      ]
    }
  ]
}
```
```

--------------------------------

### Java: Instantiate Reseller, Directory, and Site Verification Services

Source: https://developers.google.com/workspace/admin/reseller/v1/codelab/end-to-end?hl=ar

Sets up authenticated credentials and instantiates the Reseller, Directory, and Site Verification services. This example requires replacing placeholder values for the JSON private key file and reseller admin user.

```java
// OAuth2 and HTTP
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.json.jackson2.JacksonFactory;
// Directory API
import com.google.api.services.admin.directory.Directory;
import com.google.api.services.admin.directory.DirectoryScopes;
import com.google.api.services.admin.directory.model.User;
import com.google.api.services.admin.directory.model.UserMakeAdmin;
import com.google.api.services.admin.directory.model.UserName;
// Reseller API
import com.google.api.services.reseller.Reseller;
import com.google.api.services.reseller.ResellerScopes;
import com.google.api.services.reseller.model.Address;
import com.google.api.services.reseller.model.Customer;
import com.google.api.services.reseller.model.RenewalSettings;
import com.google.api.services.reseller.model.Seats;
import com.google.api.services.reseller.model.Subscription;
// Site Verification API
import com.google.api.services.siteVerification.SiteVerification;
import com.google.api.services.siteVerification.SiteVerificationScopes;
import com.google.api.services.siteVerification.model.SiteVerificationWebResourceGettokenRequest;
import com.google.api.services.siteVerification.model.SiteVerificationWebResourceGettokenResponse;
import com.google.api.services.siteVerification.model.SiteVerificationWebResourceResource;
// Java library imports
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.List;

/**
 * This is a basic example of provisioning a Google Workspace customer.
 */
public class CodelabExample {
  // Full List of scopes:
  // https://developers.google.com/identity/protocols/googlescopes
  private static final List OAUTH2_SCOPES = Arrays.asList(
    ResellerScopes.APPS_ORDER,
    SiteVerificationScopes.SITEVERIFICATION,
    DirectoryScopes.ADMIN_DIRECTORY_USER
  );

  /***************** REPLACE WITH YOUR OWN VALUES ********************************/
  public static final String JSON_PRIVATE_KEY_FILE = "path/to/json_key_file.json";
  public static final String RESELLER_ADMIN_USER = "admin@yourresellerdomain.com";
  public static final String CUSTOMER_DOMAIN = "example.com";
  public static final String CUSTOMER_SITE = "https://www.example.com/";
  /*******************************************************************************/

  public static void main(String[] args)
      throws IOException, GeneralSecurityException, FileNotFoundException {
    // Instantiate services with authenticated credentials
    GoogleCredential jsonCredentials = GoogleCredential
      .fromStream(new FileInputStream(JSON_PRIVATE_KEY_FILE));
    GoogleCredential credentials = new GoogleCredential.Builder()
      .setTransport(GoogleNetHttpTransport.newTrustedTransport())
      .setJsonFactory(JacksonFactory.getDefaultInstance())
      .setServiceAccountScopes(OAUTH2_SCOPES)
      .setServiceAccountUser(RESELLER_ADMIN_USER)
      .setServiceAccountPrivateKey(jsonCredentials.getServiceAccountPrivateKey())
      .setServiceAccountId(jsonCredentials.getServiceAccountId())
      .build();

    Reseller resellerService = new Reseller.Builder(
        credentials.getTransport(),
        credentials.getJsonFactory(),
        credentials).setApplicationName("Google Workspace Creator").build();

    Directory directoryService = new Directory.Builder(
        credentials.getTransport(),
        credentials.getJsonFactory(),
        credentials).setApplicationName("Google Workspace Creator").build();

    SiteVerification verificationService = new SiteVerification.Builder(
        credentials.getTransport(),
        credentials.getJsonFactory(),
        credentials).setApplicationName("Google Workspace Creator").build();

```

--------------------------------

### Get All Parameters for Gplus Communities

Source: https://developers.google.com/workspace/admin/reports/v1/guides/manage-usage-entities

This example retrieves a report containing all parameters for all gplus_communities entities for a specific date.

```HTTP
GET https://admin.googleapis.com/admin/reports/v1/usage/gplus_communities/all
/dates/2017-12-11
```

--------------------------------

### HTML Structure for Directory API Quickstart

Source: https://developers.google.com/workspace/admin/directory/v1/quickstart/js

This HTML file sets up the basic structure for the Directory API quickstart, including buttons for authorization and sign-out, and a preformatted area to display content. It also includes script tags for loading necessary Google APIs.

```html


  
    Directory API Quickstart
    
  
  
    

Directory API Quickstart



    
  

```

--------------------------------

### HTTP GET Request for Entity Usage Report

Source: https://developers.google.com/workspace/admin/reports/reference/rest/v1/entityUsageReports/get

This example shows a basic GET request to retrieve usage data for a specific entity type and date. It includes path parameters for entity type, entity key, and date.

```http
GET https://admin.googleapis.com/admin/reports/v1/usage/{entityType}/{entityKey or all}/dates/{date}
```