Jump to Content
Developers & Practitioners

Utilizing Cloud Support API to Programmatically Update Support Cases

August 11, 2022
https://storage.googleapis.com/gweb-cloudblog-publish/images/Cloud_Support_API_-_thumbnail.max-1300x1300.jpeg
Eugene Enclona

Cloud Technical Resident

Utilizing Cloud Support API to Programmatically Update Support Cases

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. 


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!


https://storage.googleapis.com/gweb-cloudblog-publish/images/Case_sharing_screenshot.max-1800x1800.png

(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

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.

Loading...

Step 3: Add the boilerplate code to your project

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

Loading...

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.

Loading...

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 main()

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

Posted in