aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Engineering
  • Software Engineering

Utilizing Cloud Support API To Programmatically Update Support Cases

  • aster_cloud
  • August 30, 2022
  • 5 minute read

Have you ever thought of leveraging Google Cloud’s Support API to programmatically manage your support cases? Or what if you wanted to create some scripts that can be plugged into your existing support case management system? In this blog post, I’ll walk you through how we can utilize Google Cloud’s Support API in order to solve a very particular use case a company is facing.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

 

NOTE: Be very careful when making requests to the Cloud Support API as this affects live cases that could notify live support agents when updated. If you are just testing the API, be sure to create cases with the testCase flag set to true.

 

Problem: The company wants to copy the operations team’s email alias to each support case that is open. One way to do this is to manually go through each support case in the GCP console to add the email address. But this can get very tedious, especially if they have many active support cases!

(You can manually add an email address in the console under “Case sharing” but this can be inefficient if you have a lot of support cases)

 

Solution: To solve this problem, we can write a simple Java program that will update all open cases with the email address that they want to include. This blog is going to walk you through the steps of the solution but feel free to refer to the final code here.

Before you begin:

We need to set up the following before getting started:

  1. Verify that you have a GCP account with at least Standard Support
  2. Enable “Google Cloud Support API” in your Cloud Console’s API & Services page
  3. Create a service account  with the following roles:
    1. “Organization Viewer” role or any role that grants the “resourcemanager.organizations.get” permission
    2. “Tech Support Editor” role
  4. Download the service account’s private key in a JSON format and set your environment variable “GOOGLE_APPLICATION_CREDENTIALS” to point to its path

Let’s start coding!

Step 1: Initialize a Java project

Read More  Announcing PSP's Cryptographic Hardware Offload At Scale Is Now Open Source

You’ll first need to initialize a Java project. I highly recommend using build automation tools like maven in order to do so. You may follow the quickstart guide here to initialize your Java project.

Step 2: Add dependencies for Cloud Support API

There are three main dependencies that are needed for our Java program to connect with the Cloud Support API – Google API Client Library for Java, Cloud Support API Client Library for Java (v2 beta), and Google Auth Library. Since we are using maven, it’s as simple as adding these three dependencies into your .pom file for these to be included in your Java project.

 

<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.33.2</version>
  </dependency>

  <dependency>
   <groupId>com.google.apis</groupId>
   <artifactId>google-api-services-cloudsupport</artifactId>
   <version>v2beta-rev20211103-1.32.1</version>
 </dependency>

 <dependency>
   <groupId>com.google.auth</groupId>
   <artifactId>google-auth-library-oauth2-http</artifactId>
   <version>1.4.0</version>
 </dependency>

 

Step 3: Add the boilerplate code to your project

You may use the boilerplate code that I’ve written below to simplify your code.

 

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.cloudsupport.v2beta.CloudSupport;
import com.google.api.services.cloudsupport.v2beta.model.CloudSupportCase;
import com.google.api.services.cloudsupport.v2beta.model.ListCasesResponse;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.JOptionPane;


// starter code for cloud support API to initialize it
public class App {

   // Shared constants
   static final String CLOUD_SUPPORT_SCOPE = "https://www.googleapis.com/auth/cloudsupport";

   static String projectResource = "projects/";

   public static void main(String[] args) {

       try {
           CloudSupport cloudSupport = getCloudSupportService();
           // with the CloudSupport object, you may call other methods of the Support API
           // for example, cloudSupport.cases().get("name of case").execute();

           System.out.println("CloudSupport API is ready to use: " + cloudSupport);

           projectResource = projectResource + JOptionPane.showInputDialog("Please enter   your project number: ");


       } catch (IOException e) {
           System.out.println("IOException caught! \n" + e);

       } catch (GeneralSecurityException e) {
           System.out.println("GeneralSecurityException caught! \n" + e);
       }
   }

   // helper method will return a CloudSupport object which is required for the
   // main API service to be used.
   public static CloudSupport getCloudSupportService() throws IOException, GeneralSecurityException {

       JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
       HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

       // this will only work if you have already set the environment variable
       // GOOGLE_APPLICATION_CREDENTIALS to point to the path with your service account
       // key
       GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
               .createScoped(Collections.singletonList(CLOUD_SUPPORT_SCOPE));
       HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);

       return new CloudSupport.Builder(httpTransport, jsonFactory, requestInitializer).build();
   }

}

 

Read More  What’s New With Google Cloud

This boilerplate code has one main helper function – getCloudSupportService(). This is used to authenticate your app to the Cloud Support API and create a CloudSupport object, which is the starting point for all other Cloud Support API calls.

Step 4: Write methods to update cc field of active cases

You may include the helper methods below to your app to implement the ability to update the cc field of active cases. This post assumes that you have at least one open support case.

 

public static void updateAllEmailsWith(String email) throws IOException, GeneralSecurityException {

       List<CloudSupportCase> listCases = listAllCases(projectResource);

       for (CloudSupportCase csc : listCases) {
           System.out.println("I'm going to update email address for case: " + csc.getName() + "\n");

           updateCaseWithNewEmail(csc, email);
       }
   }

   // list all open cases
   public static List<CloudSupportCase> listAllCases(String parentResource)
           throws IOException, GeneralSecurityException {

       CloudSupport supportService = getCloudSupportService();

       ListCasesResponse listCasesResponse = supportService.cases().list(parentResource).setFilter("state=OPEN")
               .execute();

       List<CloudSupportCase> listCases = listCasesResponse.getCases();

       System.out.println(
               "Printing all " + listCases.size() + " open cases of parent resource: " + parentResource);

       for (CloudSupportCase csc : listCases) {
           System.out.println(csc + "\n\n");
       }

       return listCases;
   }

   // this helper method is used in updateAllEmailsWith()
 private static void updateCaseWithNewEmail(CloudSupportCase caseToBeUpdated, String email)
     throws IOException, GeneralSecurityException {
   List<String> currentAddresses = caseToBeUpdated.getSubscriberEmailAddresses();
   CloudSupport supportService = getCloudSupportService();
    if (caseToBeUpdated.getState().toLowerCase().equals("closed")) {
      System.out.println("Case is closed, we cannot update its cc field.");
      return;
   }
    if (currentAddresses != null && !currentAddresses.contains(email)) {
     currentAddresses.add(email);
      CloudSupportCase updatedCase = caseToBeUpdated.setSubscriberEmailAddresses(currentAddresses);
      //Ensure that severity is not set. Only priority should be used, or else
     //this will throw an error.
     updatedCase.setSeverity(null);

     supportService.cases().patch(caseToBeUpdated.getName(), updatedCase).execute();
     System.out.println("I updated the email for: \n" + updatedCase + "\n");

     // must handle case when they don't have any email addresses
   } else if (currentAddresses == null) {
     currentAddresses = new ArrayList<String>();
     currentAddresses.add(email);
      CloudSupportCase updatedCase = caseToBeUpdated.setSubscriberEmailAddresses(currentAddresses);
      supportService.cases().patch(caseToBeUpdated.getName(), updatedCase).execute();
     System.out.println("I updated the email for: " + updatedCase + "\n");

   } else {
     System.out.println("Email is already there! \n\n");
   }
 }

 

Read More  Healthcare Industry Trends 2022: Data Empowers Patients, Researchers, Partners

The code snippet above has three methods:

  1. updateAllEmailsWith() 
  2. listAllCases() 
  3. updateCaseWithNewEmail()

Note that updateAllEmailsWith() has to first call listAllCases() in order to get all open support cases. Afterwards, it will call updateCaseWithNewEmail() for each open support case in order to update it to include the new email address. Also note that when calling listAllCases() you need to pass in the parent resource, which is specified in the variable projectResource. This variable is updated as the app takes in your project number as an input.

Step 5: Call updateAllEmailsWith() from <b>main()</b>

Now that we have set up our app to include all the methods we need, what remains is simply calling the method updateAllEmailsWith() with the email address that you’d like to add. It will use all the helper methods that we just wrote in order to get all open support cases and update each one with the email address that we want.

We’re done coding! Easy, right? Leveraging Cloud Support API will definitely make managing your support cases much easier. It can help automate some actions that would be very tedious to do!

Next steps: This example is just one of many different use cases that we can have for the Cloud Support API. We can also use the API to create attachments, add comments, or even search cases. Each organization may require different functionalities from Google Cloud’s Support, and these can be implemented with the use of Cloud Support API. For more information, check out the following resources bellow:

  1. Cloud Support API documentation
  2. Sample Code for Cloud Support API
  3. Google Cloud Support General Documentation
  4. Technical Support Services Guidelines

 

 

By: Eugene Enclona (Cloud Technical Resident)
Source: Google Cloud Blog


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster_cloud

Related Topics
  • API
  • Cloud Support API
  • Google Cloud
  • Java
  • Tutorials
You May Also Like
Web
View Post
  • Engineering
  • Software Engineering

Mastering the Art of Load Testing for Web Applications

  • November 29, 2023
Ubuntu. Chiselled containers.
View Post
  • Engineering
  • Technology

Canonical Announces The General Availability Of Chiselled Ubuntu Containers

  • November 25, 2023
Brush, Color, and Sketch pad
View Post
  • Cloud-Native
  • Design
  • Engineering

6 Security Best Practices For Cloud-Native Applications

  • November 17, 2023
Ingrasys
View Post
  • Computing
  • Engineering
  • Technology

Ingrasys Unveils Next-Gen AI And Cooling Solutions At Supercomputing 2023

  • November 15, 2023
Malware, Security, and Laptop
View Post
  • Engineering
  • Technology

Singapore And Google Partner On Web Risk To Protect Citizens From Online Scams And Phishing

  • November 12, 2023
View Post
  • Engineering
  • Public Cloud

Golang’s GORM Support For Cloud Spanner Is Now Generally Available

  • November 9, 2023
Cloud
View Post
  • Design
  • Engineering
  • Public Cloud

The Impact Of Public Cloud Price Hikes

  • November 8, 2023
View Post
  • Engineering

Finding Stability in Open Source Work

  • November 2, 2023

Stay Connected!
LATEST
  • Birthday Cake 1
    How ChatGPT Altered Our World in Just One Year
    • November 30, 2023
  • OpenAI 2
    Sam Altman Returns As CEO, OpenAI Has A New Initial Board
    • November 30, 2023
  • Web 3
    Mastering the Art of Load Testing for Web Applications
    • November 29, 2023
  • Data center. Servers. 4
    Intel Granulate Optimizes Databricks Data Management Operations
    • November 27, 2023
  • Ubuntu. Chiselled containers. 5
    Canonical Announces The General Availability Of Chiselled Ubuntu Containers
    • November 25, 2023
  • Cyber Monday Sale. Guzz. Ideals collection. 6
    Decode Workweek Style with guzz
    • November 23, 2023
  • Guzz. Black Friday Specials. 7
    Art Meets Algorithm In Our Exclusive Shirt Collection!
    • November 23, 2023
  • Presents. Gifts. 8
    25 Besties Bargain Bags Below $100 This Black Friday 2023
    • November 22, 2023
  • Electronics 9
    Top 10+1 You Can’t Do Without For The Holidays: Electronics Edition.
    • November 20, 2023
  • Microsoft. Windows 10
    Ousted Sam Altman To Lead New Microsoft AI Team
    • November 20, 2023
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • Oracle | Microsoft 1
    Oracle Cloud Infrastructure Utilized by Microsoft for Bing Conversational Search
    • November 7, 2023
  • Riyadh Air and IBM 2
    Riyadh Air And IBM Sign Collaboration Agreement To Establish Technology Foundation Of The Digitally Led Airline
    • November 6, 2023
  • Ingrasys 3
    Ingrasys Unveils Next-Gen AI And Cooling Solutions At Supercomputing 2023
    • November 15, 2023
  • Cloud 4
    DigitalOcean Currents Report Finds That Adoption Of AI/ML, And Investments In Cybersecurity And Multi-Cloud Strategies Are On The Rise At Small Businesses
    • November 9, 2023
  • Portrait of Rosalynn Carter, 1993 5
    Former First Lady Rosalynn Carter Passes Away at Age 96
    • November 19, 2023
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.