How to create Service Account and enable Google Cloud API

To work with Google’s APIs, you need to create a Service Account in Google Cloud Platform and download a JSON file containing the account details. After creating the account, you just need to enable the Google Cloud APIs you need, and you can start using the Service Account in your apps and Python code. Follow the steps in this article to get started quickly.

What is a Service Account?

A Service Account is a special type of account that is often used to call APIs from apps and code. It is authorized to act on behalf of the main user of the Google service, so it can do many tasks for you in the Google products you use.

PasswordNone. It can’t sign in with a browser or cookies.
AuthenticationUses public/private RSA key pairs instead of a password.
AuthorizationCan be granted permissions like a user account.
Google WorkspaceNot counted as a user when sharing assets in Google Workspace.

Create a Service Account

Step 1: You need to create a Project to contain one or more Service Accounts. Go to console.cloud.google.com/projectcreate to create a new Project.

Create a Project before creating a Service Account
Create a Project before creating a Service Account

Step 2: Fill in the basic information for the Project. Note that the Project ID is permanent and can’t be changed later. If you don’t have a Location, just leave it as No organization.

Fill in the information to create a Project
Fill in the information to create a Project

Step 3: After creating the Project, make sure you select the Project you want to create the Service Account in.

Choose your Project
Choose your Project

Step 4: Open the Service Account management page by clicking IAM & Admin > Service Accounts.

Access the Service Account management page
Access the Service Account management page

Step 5: Click the Create Service Account button.

Click Create Service Account to create a Google service account
Click Create Service Account to create a Google service account

Step 6: Fill in the details for the Service Account. Keep the Service account ID short and readable, because it becomes an email address you’ll use a lot later. When asked to grant roles, skip this step and don’t give it the Owner role. To read and write Google Sheets or Google Drive files, the Service Account doesn’t need any project role; it only needs to be shared on the specific files. This follows the principle of least privilege: if the JSON key file ever leaks, the attacker can only reach the files you shared, not your whole Google Cloud project.

Fill in the details to create a Service Account
Fill in the details to create a Service Account

Step 7: Open Manage keys for your Service Account by clicking the options button (three dots). This is where you create the JSON file containing the account credentials.

Open Manage keys
Open Manage keys

Step 8: Click Add Key and select Create new key to generate a private key.

Generate a private key for your Service Account
Generate a private key for your Service Account

Step 9: Select JSON and click Create to create a JSON key file for your Service Account.

Select JSON and click the Create button
Select JSON and click the Create button

Step 10: Your browser will download the JSON file to your computer right away. Click Close to finish.

Once the JSON file is downloaded, you're done
Once the JSON file is downloaded, you’re done

Here is an example of what the JSON file looks like. It contains the credentials for your Service Account, so treat it like a password: don’t send it over chat, commit it to GitHub, or leave it in a public folder. If you think it has been exposed, delete that key and create a new one. If you use Python, you can create a dictionary variable with exactly the same content as this JSON file to work with Google’s APIs.

The content in the JSON file contains your Service Account access information
The content in the JSON file contains your Service Account access information

Enable Google Cloud APIs

Once you’ve created a Service Account, you need to enable the APIs it will use, so that your API calls work.

Step 1: Open the Google Cloud API library by clicking APIs & Services > Library.

Go to the library to enable the Google Cloud API
Go to the library to enable the Google Cloud API

Step 2: Search for the APIs you want to use. Each API’s description explains what it does. Here are a few popular examples.

  • Google Drive API: Lets you create files, manage file sharing, and search for files and folders.
  • Google Sheets API: Lets you read and edit the content of worksheets.
Find the APIs you want to use in the Google Cloud API Library
Find the APIs you want to use in the Google Cloud API Library

Step 3: Enable the API you selected.

Enable a Google Cloud API
Enable a Google Cloud API

Step 4: The overview page shows the usage data for the API. You can turn an API off by clicking the Disable API button.

You can disable the API on the overview page
You can disable the API on the overview page

Finally, depending on how you use the API, you may need to give this Service Account edit access, for example to a Google Drive folder or a Google Sheets file. The Service Account’s email is the client_email value in the JSON file on your computer. Share only the files or folders it actually needs, with Editor access if it has to write data or Viewer access if it only reads.

Give edit access to the Service Account's client email
Give edit access to the Service Account’s client email
Video tutorial for creating a Service Account and enabling Google Cloud API

Frequently asked questions

Why do I still get errors when calling an API that is already enabled?

Some APIs only work if you give edit access to the client email. Check whether you’ve shared the file or folder with the Service Account’s client email.

What should I do if I lose the Service Account JSON file?

You can’t download the JSON file with an existing private key again. However, you can delete the old key and create a new one.

Conclusion

I hope this article helps you create a Google Service Account quickly and smoothly. I’m still learning and working with Google Cloud myself, and I hope to share more of my experience with you in the future. Feel free to leave a comment below if you have questions or just want to chat.

Hieu Tran Ngoc Minh

Hieu (born in 1996) holds a Bachelor's degree in Business Administration from Saigon Technology University. Currently a Data Analyst at Ninja Van, Hieu has extensive experience in Data Analysis and Digital Marketing. This blog is where Hieu shares practical experiences from work and life.

2 Comments

  1. Clear and actionable guide! This tutorial simplifies creating a service account and enabling Google Cloud APIs with step-by-step precision excellent work!

    Reply

Leave a Comment

Feel free to leave your comment (preferably in English), and we will review and respond as soon as possible. Please use a real email to ensure your comment is approved and to receive notifications when we reply. You can also add an avatar to your email.